Android的 - 如何获取振动环状态? [英] Android - How to get Vibrate on ring status?
本文介绍了Android的 - 如何获取振动环状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ICS和JB有一个操作系统设置:上时振动环。我想接下来的code尝试获取状态,但值是不一样的。有没有广播或其他方式,我可以用?
ICS and JB has a OS setting: "Vibrate on ring". I tried next code try to get the status, but the values are not the same. Is there Broadcast or other method I could use?
AudioManager audioManager = (AudioManager) this.getApplicationContext()
.getSystemService(Context.AUDIO_SERVICE);
boolean bVibrateRing = audioManager
.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER);
在ICS音效模式,当检查时振动环,这将是真实的。 但是,在JB这将是错误的。
In ICS Sound mode and when check the "Vibrate on ring", it will be true. But in JB it will be false.
我试过广播是这样的:
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
int nstate = extras
.getInt(AudioManager.EXTRA_RINGER_MODE);
Log.d("receiver", " receiver EXTRA_RINGER_MODE : "
+ nstate);
}
}
};
IntentFilter filter = new IntentFilter(
AudioManager.RINGER_MODE_CHANGED_ACTION);
registerReceiver(receiver, filter);
我只能得到一个方式的变化:
I could only get next mode change:
RINGER_MODE_NORMAL
RINGER_MODE_SILENT
RINGER_MODE_VIBRATE
有没有关于对时振动环的信息。
There is no information about "Vibrate on ring".
感谢您的任何提示和时间。
Thank you for your any hint and time.
推荐答案
下一步code可以检查状态:
Next code could check the status:
Settings.System.getInt(this.getApplicationContext().getContentResolver(),
"vibrate_when_ringing", 0);
这篇关于Android的 - 如何获取振动环状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文