How can I change programmatically a global setting like 'haptic feedback'?
(Manually you can change this setting in 'Sound & Display Settings')Changing e.g. the airplane mode can be done with the following code:
private void setAirplaneMode(boolean bOn)
{
Settings.System.putInt(getContentResolver(),
Settings.System.AIRPLANE_MODE_ON,
bOn ? 1 : 0);
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", bOn ? 1 : 0);
sendBroadcast开发者_Go百科(intent);
}
However, for 'haptic feedback' this does not work because I don't find a corresponding intent.
Simply
private void setHapticFeedbackMode(boolean bOn)
{
Settings.System.putInt(getContentResolver(),
Settings.System.HAPTIC_FEEDBACK_ENABLED,
bOn ? 1 : 0);
}
does not work (I guess a broadcast of an intent is really necessary).
I am not interested in things like setHapticFeedbackEnabled
, because in that way you are only changing the way how the calling app/view is handling haptic feedback.
I am looking for a way to change the global setting. (Like if you were checking/unchecking the checkbox in 'Sound & Display Settings' manually.)
Settings.System.putInt(getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED, 0);
This does work for me. You have set the WRITE_SETTINGS
permission in your manifest I assume.
Have you tried using VIBRATE_SETTING_CHANGED
or RINGER_MODE_CHANGED
? These are provided in the broadcast intent list under SDK's platforms/android-x/data/broadcast_actions.txt
.
精彩评论