0

我目前正在尝试将运行 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)并没有任何作用:如果我处于...

4

1 回答 1

1

刚刚发现可以通过 NotificationListener Service 实现。(而且我的问题在其他地方已经有了答案……)

    //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);

    }
于 2015-09-12T10:34:48.347 回答