Android - Push Notification are ON?
Asked Answered
C

2

13

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?

enter image description here

Thanks

Christean answered 4/6, 2013 at 8:1 Comment(4)
As far as I know, you can't turn off those notifications. If you check Notification and NotificationManager you won't see any method that allows to get that information. I could be wrong though.Rundlet
Maybe #4422027 could help.Kyanize
Is it correct then that you need to de-install the app if you never want to receive a new push message regarding it?Purington
possible duplicate of Android 4.1: How to check notifications are disabled for the application?Omland
I
8

Assuming you are referring to Google Cloud Messaging (since you are using the android and push-notification tag), there are no general settings used to enable/disable the GCM service (unlike the Apple Push Notifications service for iOS devices).

When you install an app, if the app uses Google Cloud Messaging, it will be listed in the list of permissions that this app requires in order to work. By choosing to install the app you allow it to send push notifications to you.

That said, in order for the app to actually receive GCM messages, your app must programmatically register to the GCM service. You can do that in any place you wish within your app, and you can create an app settings activity (or fragment or whatever) in which the user can enable/disable GCM (which would trigger registration/unregistration to/from GCM). Your app can contain a persistent store that would hold the registration ID you receive upon registration to GCM, and you can use that store to determine if your app in registered to GCM.

You can ask your user to turn it on if the app is already running (if you have some code that does that). If it's not running and the app is not registered for GCM on that device, your server can't send GCM messages to it.

If you want to overcome that obstacle, you can register to GCM automatically (when the app is first launched). Then you can send messages to the app whenever you wish. If you still want to let the user decide whether they want to see those notifications, you can have a flag in your app settings that enables/disables the UI notification that you create as a result of an incoming GCM message. The GCM service will always be enabled, but unless the user chooses to view the notifications, you app won't display anything when a GCM message arrives.

Inurbane answered 4/6, 2013 at 14:49 Comment(5)
So If I understand it right, "show notification" in app settings is just to hide all "popups" from the app? For example I can still receive notification, store them and show as a dialog when user enter the app.Christean
@Christean I'm not sure which app settings you are referring to. Are you referring to specific app settings within a specific app? If you are referring to notifications that arrive from the GCM service, it's up to you do decide how to write your app (whether to automatically register to GCM and always stay registered, which will allow you to always receive notifications).Inurbane
By app settings I mean Settings -> App Manager -> App info, there is small "tick" option called "Show notifications"Christean
@Christean Which device/Android version are you using? I don't have it on my Android device (which is relatively old).Inurbane
@Christean Sorry about that, I have S with 2.2, and I don't have that checkbox, so I wasn't aware of it. I thought you were referring to some settings in a specific app.Inurbane
C
3

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);
}
Cloven answered 27/8, 2013 at 1:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.