《M 调节音量要求发出声音.pdf》由会员分享,可在线阅读,更多相关《M 调节音量要求发出声音.pdf(3页珍藏版)》请在三一文库上搜索。
1、 调节音量发出声音调节音量发出声音 功能描述: 在调节音量的时候 M 版本没有声音,客户要求有声音提示 功能实现: 1. path: frameworksbasepackagesSystemUIsrccomandroidsystemuivolumeVolumeDialogController.java 1) import android.media.ToneGenerator; / prize caoshaowei 20161024 add 2) / prize caoshaowei 20161024 add start private ToneGenerator playToneGenera
2、tors; private int prevAudibleStreamVolume = -1; / prize caoshaowei 20161024 add end 3) public VolumeDialogController(Context context, ComponentName component) mContext = context.getApplicationContext(); . / prize caoshaowei 20161024 add start if(playToneGenerators = null) playToneGenerators = new To
3、neGeneratorAudioSystem.getNumStreamTypes(); / prize caoshaowei 20161024 add end 4) / prize caoshaowei 20161024 add start private void onStopSounds() synchronized (this) int numStreamTypes = AudioSystem.getNumStreamTypes(); for (int i = numStreamTypes - 1; i = 0; i-) ToneGenerator toneGen = playToneG
4、eneratorsi; if (toneGen != null) toneGen.stopTone(); / prize caoshaowei 20161024 add end 5) private void onVolumeChangedW(int stream, int flags) . if (showSilentHint) mCallbacks.onShowSilentHint(); / prize caoshaowei 20161024 add start onStopSounds(); if (flags catch (RuntimeException e) Log.d(TAG,
5、ToneGenerator constructor failed with + RuntimeException: + e); synchronized (this) final ToneGenerator toneGen = playToneGeneratorsstream; if (toneGen != null) toneGen.startTone(ToneGenerator.TONE_PROP_BEEP); new Handler().postDelayed(new Runnable() Override public void run() onStopSounds(); , 150); prevAudibleStreamVolume = lastAudibleStreamVolume; / prize caoshaowei 20161024 add end if (changed