mutable2112
mutable2112

Reputation: 479

Android checkSelfPermission for push Notifications

My issue is that I am not sure what String key to use to check for Notification permissions. For key

"com.google.android.c2dm.permission.RECEIVE"

this code always returns true, even if I remove the permission from my Manifest:

                int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), "com.google.android.c2dm.permission.RECEIVE");
            if (permissionCheck==PackageManager.PERMISSION_GRANTED) {
                Log.d("granted","TRUE");
            }

I also tried other permission strings like 'mypkg.permission.C2D_MESSAGE'.

If this is because the Notification permission in the system is considered "normal" and not "dangerous", then how do I detect if the user has disabled Notifications for my app in phone settings (like attached image)?

enter image description here

Upvotes: 4

Views: 3001

Answers (1)

Prerak Sola
Prerak Sola

Reputation: 10009

You don't need permissions for notification check.

You can use NotificationManagerCompat.areNotificationsEnabled() method of the support library. You can use this on API 19+, and for the APIs below this, it always returns true.

Upvotes: 5

Related Questions