2017-04-11 71 views
1

我想知道我的應用程序是否被允許顯示通知。所以我找到了this方法areNotificationsEnabled()未定義類型NotificationManagerCompat

於是我就用我的應用程序這個簡單的功能使用Eclipse,和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(); 
    } 

但我得到一個編譯錯誤

的方法areNotificationsEnabled()是未定義對於類型 NotificationManagerCompat

回答

1

您的代碼是錯誤的。 areNotificationsEnabled()支持庫docs)的版本24.0.0開始可用,而不是Android平臺。它看起來你正在使用一些舊版本的庫。同時檢查平臺版本在這種情況下是無用的,並且可以安全地移除。

+0

謝謝。 https://developer.android.com/topic/libraries/support-library/revisions.html – Ton

相關問題