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();
}

你可能感兴趣的:(Android)