首页 > 解决方案 > 无法以编程方式在 Gionee A1 中打开静音模式

问题描述

嘿,我正在使用下面的代码将设备变成静音模式

public static void setDeviceOnSilent(Context context) {

    AudioManager audioManager = (AudioManager) context.getSystemService(AUDIO_SERVICE);
    audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}

上面的代码在除金立 A1之外的所有设备上都能正常工作。请建议我已经授予NotificationAccessPolicyEnabled权限的问题是什么。下面是代码。

public static boolean isNotificationAccessPolicyEnabled(Context context) {
    NotificationManager notificationManager;
    notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
            && !notificationManager.isNotificationPolicyAccessGranted()) {

        Intent intent = new Intent(
                android.provider.Settings
                        .ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);

        context.startActivity(intent);

        return false;
    }
    return true;
}

标签: androidbroadcastreceiver

解决方案


代码看起来还不错。检查清单以获得必要的权限。


推荐阅读