如何在程序中检查用户是否在应用设置中关闭了推送通知?我能否直接从应用程序打开应用程序设置意图以提示用户打开它?谢谢。
除非声明系统进程或具有root权限,否则无法访问此属性。首先,您可以查看文件的权限:/data/system/notifycaiton_policy.xml: -wr------。
另一种方法是查看源代码:/android/4.2/frameworks/base/services/java/com/android/server/NotificationManagerService.java。 在api中:public void setNotificationsEnabledForPackage(String pkg, boolean enabled)
,将检查调用者的UID是否为Process.SYSTEM_UID
:
void checkCallerIsSystem() {
int uid = Binder.getCallingUid();
if (UserHandle.getAppId(uid) == Process.SYSTEM_UID || uid == 0) {
return;
}
throw new SecurityException("Disallowed call for uid " + uid);
}