Android開啟關閉觸控提示音
1.啟動應用程式的時候關閉系統的觸控聲音
public void DisTouchEffectAndSaveState() {
SharedPreferences setting = this.getSharedPreferences("SystemSetting", MODE_PRIVATE);
int mSoundEffect = setting.getInt("SOUND_EFFECTS_ENABLED", -1);
if (mSoundEffect == -1) {
SharedPreferences.Editor editor = setting.edit();
mSoundEffect = Settings.System.getInt(this.getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, 0);
editor.putInt("SOUND_EFFECTS_ENABLED", mSoundEffect);
editor.commit();
}
AudioManager mAudioManager = (AudioManager) getSystemService(Service.AUDIO_SERVICE);
mAudioManager.unloadSoundEffects();
Settings.System.putInt(this.getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, 0);
}
2.退出應用的時候恢復原來設定
public void RecoveryTouchEffect() {
SharedPreferences setting = this.getSharedPreferences("SystemSetting", MODE_PRIVATE);
int mSoundEffect = setting.getInt("SOUND_EFFECTS_ENABLED", 0);
AudioManager mAudioManager = (AudioManager) getSystemService(Service.AUDIO_SERVICE);
Settings.System.putInt(this.getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, mSoundEffect);
mAudioManager.loadSoundEffects();
}