如何以编程方式更改像“触觉反馈”全局设置? [英] How to change programmatically a global setting like 'haptic feedback'?

查看:162
本文介绍了如何以编程方式更改像“触觉反馈”全局设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎样才能改变编程的全局设置,如触觉反馈?结果
(手动您可以更改此设置声音和放大器;显示设置')

例如更改飞行模式可以用下面code来完成:

 私人无效setAirplaneMode(布尔BON)
{
    Settings.System.putInt(getContentResolver(),
                           Settings.System.AIRPLANE_MODE_ON,
                           BON? 1:0);    意向意图=新意图(Intent.ACTION_AIRPLANE_MODE_CHANGED);
    intent.putExtra(国家,BON 1:0);
    sendBroadcast(意向);
}

不过,对于触觉反馈,这并不工作,因为我没有找到相应的意图。

简单

 私人无效setHapticFeedbackMode(布尔BON)
{
     Settings.System.putInt(getContentResolver(),
                            Settings.System.HAPTIC_FEEDBACK_ENABLED,
                            BON? 1:0);
}

不工作(我猜的意图的广播是真正必要的)。

我不感兴趣,如 setHapticFeedbackEnabled 的事情,因为这样你只更改调用应用程序/视图是如何处理的触觉反馈的方式。
我正在寻找一种方法来改变全局设置。 (就像如果你被选中/取消选中的复选框中的声音和放大器;显示设置。手动)


解决方案

  Settings.System.putInt(getContentResolver(),Settings.System.HAPTIC_FEEDBACK_ENABLED,0);

这也为我工作。您已设置了 WRITE_SETTINGS 许可,在你的清单我承担。

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(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.

这篇关于如何以编程方式更改像“触觉反馈”全局设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆