Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 218
mutable2112 Avatar asked Sep 10 '25 16:09

mutable2112


1 Answers

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.

like image 166
Prerak Sola Avatar answered Sep 13 '25 06:09

Prerak Sola