How to request Do Not Disturb permission on Samsung S5 (SM-G800H)?

蓝咒 提交于 2019-12-24 18:53:00

问题


This is the usual way to request DND permission:

Intent intent = new Intent();
intent.setAction("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS");
startActivityForResult(intent, NOTIFICATION_REQUEST_CODE);

However on (at least one) Samsung SM-G800H this throws ActivityNotFoundException.

Apparently on that model they have something called 'Blocking Mode'. Anyone know the correct intent / how to handle on that model? See https://www.cnet.com/uk/how-to/where-to-find-do-not-disturb-mode-on-the-galaxy-s5/

Device details: Manufacturer: Samsung Model: SM-G800H Board: Msm8228 Android API: 23 Android OS: 6.0.1 Brand: Samsung RAM: 1.35GB Orientation: Portrait


回答1:


This might not be a Samsung related issue. According to the official docs, ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS is available only on API 23+ (Marshmallow). Does the S5 you're testing on have Android 6 Marshmallow running? If not, that's your problem.

EDIT: Since this Activity may not be present on each device even if they are on Android 6, you'll need to handle the case where the intent can't be resolved. So something like this might be what you want:

PackageManager packageManager = getActivity().getPackageManager();

Intent intent = new Intent();
intent.setAction("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS");

if (intent.resolveActivity(packageManager) != null) {
    startActivityForResult(intent, NOTIFICATION_REQUEST_CODE);
} else {
    Log.d(TAG, "No Intent available to handle action");
}


来源:https://stackoverflow.com/questions/47595762/how-to-request-do-not-disturb-permission-on-samsung-s5-sm-g800h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!