【问题标题】:How to set maximum sound on Android 7.1如何在 Android 7.1 上设置最大声音
【发布时间】:2017-12-19 09:50:14
【问题描述】:

打开应用程序声音设置为最大。

NotificationManager n = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
        if(n.isNotificationPolicyAccessGranted()) {
            AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
            mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, maxVolume, 15);

        }else{
            // Ask the user to grant access
            Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
            startActivityForResult(intent,99);
        }

我在 android 7.1.1 中使用过这段代码,但没有运气。 你能帮帮我吗?

【问题讨论】:

    标签: android audio volume android-audiomanager android-7.1-nougat


    【解决方案1】:

    我在 android 7.1.1 上使用过这段代码,但没有运气。

    因为从 N 起,除非应用已获得“请勿打扰”访问权限,否则不允许进行可切换“请勿打扰”的音量调整。见isNotificationPolicyAccessGranted().

    boolean isNotificationPolicyAccessGranted ()

    在 API 级别 23 中添加

    检查调用包的读取/修改通知请勿打扰策略的能力。

    如果调用包可以读取/修改通知策略,则返回 true。

    阅读更多关于setStreamVolume()AudioManager

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多