Android - Push Notification are ON?

后端 未结 2 1165
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 09:12

How to check programmatically if user turn off push notification in app settings? Can I open app settings intent directly from the app to prompt user to turn it on?

2条回答
  •  不思量自难忘°
    2020-12-31 09:30

    you can't access this property unless you declare the system process or have root permission, first you can see the permission of file: /data/system/notifycaiton_policy.xml: -wr------。

    In aother way, see the source code of: /android/4.2/frameworks/base/services/java/com/android/server/NotificationManagerService.java. in api: public void setNotificationsEnabledForPackage(String pkg, boolean enabled), there will check the caller's UID whether be 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);
    }
    

提交回复
热议问题