How can I change programmatically a global setting like haptic feedback ?
(Manually you can change this setting in Sound & Display Settings )
• 改变飞机模式,可采用以下代码:
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(intent);
}
然而,对于 ha语反馈,这并不奏效,因为我没有找到相应的意图。
简单
private void setHapticFeedbackMode(boolean bOn)
{
Settings.System.putInt(getContentResolver(),
Settings.System.HAPTIC_FEEDBACK_ENABLED,
bOn ? 1 : 0);
}
并不奏效(我猜想广播某种意图确实是必要的)。
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.)