资源描述:
《android+静音与马达振动流程》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、android静音与马达振动流程1,设置静音和振动静音和振动都属于来电后的动作.所以在设置静音和振动时都只是设置一些标识,并往数据库写入相应标识.文件:packages/apps/settings/src/com/android/settings/SoundAndDisplaySettings.javaprivateCheckBoxPreferencemSilent;privateCheckBoxPreferencemVibrate;privatevoidsetRingerMode(booleansilent,booleanvibrate){if(silent){mAudio
2、Manager.setRingerMode(vibrate?AudioManager.RINGER_MODE_VIBRATE:AudioManager.RINGER_MODE_SILENT);}else{mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,vibrate?AudioManager.VIBRATE_SETTING_ON:AudioManager.VIBRATE_SE
3、TTING_OFF);}}publicbooleanonPreferenceTreeClick(PreferenceScreenpreferenceScreen,Preferencepreference){if(preference==mSilent
4、
5、preference==mVibrate){setRingerMode(mSilent.isChecked(),mVibrate.isChecked());if(preference==mSilent)updateState(false);}...静音和振动是复选框按钮,两个中有一个发生变化时调用setRingerMode对状
6、态进行设置;如下状态描术:RINGER_MODE_SILENT静音,且无振动RINGER_MODE_VIBRATE静音,但有振动RINGER_MODE_NORMAL正常声音,振动开关由setVibrateSetting决定.铃响模式的设置是通过mAudioManager(音频管理器)来实现的.2音频管理器服务mAudioManager所在服务如下:文件:frameworks/base/media/java/android/media/AudioManager.javapublicstaticfinalintRINGER_MODE_SILENT=0;publicstaticfi
7、nalintRINGER_MODE_VIBRATE=1;publicstaticfinalintRINGER_MODE_NORMAL=2;publicvoidsetRingerMode(intringerMode){IAudioServiceservice=getService();try{service.setRingerMode(ringerMode);}catch(RemoteExceptione){Log.e(TAG,"DeadobjectinsetRingerMode",e);}}将铃响模式值传给音频接口服务IaudioServicepublicstaticfina
8、lintVIBRATE_TYPE_RINGER=0;publicstaticfinalintVIBRATE_TYPE_NOTIFICATION=1;publicstaticfinalintVIBRATE_SETTING_OFF=0;publicstaticfinalintVIBRATE_SETTING_ON=1;publicstaticfinalintVIBRATE_SETTING_ONLY_SILENT=2;publicvoidsetVibrateSetting(intvibrateTyp,intvibrateSetting){IAudioServiceservice=ge
9、tService();try{service.setVibrateSetting(vibrateType,vibrateSetting);}catch(RemoteExceptione){Log.e(TAG,"DeadobjectinsetVibrateSetting",e);}}将振动类型和振动设置传给音频接口服务IaudioService,IaudioService的定义如下:frameworks/base/media/java/android/media/IAudioService.aidlfra