安卓,静音模式通知静音、模式、通知

2023-09-07 16:27:16 作者:- 小争小吵小任性 ﹌

在我的Andr​​oid应用程序,我需要知道,每当用户在手机的选择模式(当您按住了一段时间的电源按钮时出现的一个),并推动了静音模式按钮。我发现,飞行模式被链接到 ACTION_AIRPLANE_MODE_CHANGED 。但是,我找不到任何操作事件为静音模式按钮?

In my android app I need to know, whenever the user is in Phone options mode (the one that appears when you hold down the power button for a while), and pushes the 'Silent mode' button. I have found that Airplane mode is linked to the ACTION_AIRPLANE_MODE_CHANGED. But I can not find any action event for the 'Silent mode' button?

推荐答案

AudioManager 提供了 getRingerMode()方法,它可以用于确定当前状态。 你的情况,你必须查询 AudioManager.RINGER_MODE_SILENT 返回值,所以像

The AudioManager provides a getRingerMode() method which can be used to determine the current state. In your case you have to query the returned value for AudioManager.RINGER_MODE_SILENT, so something like

AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

if (am.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
    // do something neat here
}

在与组合AudioManager的 RINGER_MODE_CHANGED_ACTION 这应该为你工作。

In combination with AudioManager's RINGER_MODE_CHANGED_ACTION this should work for you