问题
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