我目前正在尝试将运行android 5.1的手机设置为优先模式。
我试图在AudioManager中将其设置为静音模式,但是将其设置为零也没有效果。
虽然将其设置为振动模式仍然可以...
//Neither this
AudioManager am = (AudioManager) getBaseContext().getSystemService(AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
//nor this works
AudioManager am = (AudioManager) getBaseContext().getSystemService(AUDIO_SERVICE);
am.setRingerMode(0);
到目前为止,我还没有找到其他解决方案。
我也不能使用任何根功能。
编辑:刚刚发现将其设置为0(或RINGER_MODE_SILENT)不会做任何事情:如果我在...中,它将带我退出振动模式。
最佳答案
刚发现我可以通过NotificationListener服务实现它。
(而且我的问题在其他地方已经有答案了……)
//In the Service I use this to enable and disable silent mode(or priority...)
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
boolean start = intent.getBooleanExtra("start", false);
if(start)
{
Log.d("TAG","START");
//Check if at least Lollipop, otherwise use old method
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
requestInterruptionFilter(INTERRUPTION_FILTER_NONE);
else{
AudioManager am = (AudioManager) getBaseContext().getSystemService(AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
}
else
{
Log.d("TAG","STOP");
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
requestInterruptionFilter(INTERRUPTION_FILTER_ALL);
else{
AudioManager am = (AudioManager) getBaseContext().getSystemService(AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
}
return super.onStartCommand(intent, flags, startId);
}
关于android - Android 5.1设为优先模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32531819/