Ton
Ton

Reputation: 9746

The method areNotificationsEnabled() is undefined for the type NotificationManagerCompat

I want to know if my app is allowed to display notifications. So I found this.

So I use this easy function in my app using Eclipse, and android:targetSdkVersion="24"

  @TargetApi(24)
  static boolean AreNotificationsEnabledForMyApp(Context myContext) {
     if (Build.VERSION.SDK_INT < 24)
        return true; //there is no way to know this in earlier Android releases so I return true.

     NotificationManagerCompat nmc = NotificationManagerCompat.from(myContext);
     return nmc.areNotificationsEnabled();
  }

But I get a compile error

The method areNotificationsEnabled() is undefined for the type NotificationManagerCompat

Upvotes: 1

Views: 1578

Answers (1)

Marcin Orlowski
Marcin Orlowski

Reputation: 75645

Your code is wrong. areNotificationsEnabled() is available since version 24.0.0 of support library (docs), not the Android platform. It looks you are using some older version of the library. Also check of platform version is useless in this case and can be safely removed.

Upvotes: 1

Related Questions