Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android NotificationManagerCompat.areNotificationsEnabled not working

How does NotificationManagerCompat.areNotificationsEnabled() work? I have tried to do the following appPushEnabled = String.valueOf(NotificationManagerCompat.areNotificationsEnabled()); however it is giving me an error?

Also it says it only works on some devices do I need a try catch on it?

like image 331
Adam Katz Avatar asked Jun 24 '16 14:06

Adam Katz


3 Answers

After testing for few hours, here is what I have found.

In App Gradle file, com.android.support:support should be minimum 24 and compileSdkVersion has to be 24

android {    
    compileSdkVersion 24      
}    
dependencies {
     compile 'com.android.support:support-v4:24.0.0'
}

And then @petey 's answer will be working

NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context);
boolean areNotificationsEnabled = notificationManagerCompat.areNotificationsEnabled();
like image 87
sasha Avatar answered Nov 11 '22 17:11

sasha


Try using NotificationManagerCompat.from(Context context) method to get an instance of a NotificationManagerCompat object you may then be able to call areNotificationsEnabled() on.

NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context)
boolean areNotificationsEnabled = notificationManagerCompat.areNotificationsEnabled();
String appPushEnabled = String.valueOf(areNotificationsEnabled);
like image 6
petey Avatar answered Nov 11 '22 16:11

petey


You should set your gradle with
compile "com.android.support:support-v4:24.0.0" minimum.

like image 1
Hichem Laroussi Avatar answered Nov 11 '22 18:11

Hichem Laroussi