Example usage for android.app NotificationManager areNotificationsEnabled

List of usage examples for android.app NotificationManager areNotificationsEnabled

Introduction

In this page you can find the example usage for android.app NotificationManager areNotificationsEnabled.

Prototype

public boolean areNotificationsEnabled() 

Source Link

Document

Returns whether notifications from the calling package are blocked.

Usage

From source file:com.keylesspalace.tusky.util.NotificationHelper.java

public static boolean areNotificationsEnabled(@NonNull Context context,
        @NonNull AccountManager accountManager) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

        // on Android >= O, notifications are enabled, if at least one channel is enabled
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        //noinspection ConstantConditions
        if (notificationManager.areNotificationsEnabled()) {
            for (NotificationChannel channel : notificationManager.getNotificationChannels()) {
                if (channel.getImportance() > NotificationManager.IMPORTANCE_NONE) {
                    Log.d(TAG, "NotificationsEnabled");
                    return true;
                }//from   w ww. ja va  2s .  co  m
            }
        }
        Log.d(TAG, "NotificationsDisabled");

        return false;

    } else {
        // on Android < O, notifications are enabled, if at least one account has notification enabled
        return accountManager.areNotificationsEnabled();
    }

}