Example usage for android.app NotificationManager IMPORTANCE_NONE

List of usage examples for android.app NotificationManager IMPORTANCE_NONE

Introduction

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

Prototype

int IMPORTANCE_NONE

To view the source code for android.app NotificationManager IMPORTANCE_NONE.

Click Source Link

Document

A notification with no importance: does not show in the shade.

Usage

From source file:com.sxt.chat.activity.NotifycationActivity.java

/**
 * ??/*w w w .  j  a  v a  2s .  co  m*/
 *
 * @param id ID
 */
public void sendNotification(int id, final String body) {

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationChannel hahahah = helper.getManager().getNotificationChannel(DEFAULT_CHANNEL);
        Log.e("NotificationChannel", String.format("importance %s , flag %s",
                hahahah.getImportance() == NotificationManager.IMPORTANCE_NONE, hahahah.getImportance()));

    }

    final NotificationCompat.Action action = new NotificationCompat.Action(
            R.drawable.ic_ar_photo_main_blue_24dp, String.valueOf("~"),
            getPendingIntent(this, MainActivity.class));
    switch (id) {
    case NOTI_1:
        helper.notify(NOTI_ID_1--, helper.buildNotificationText(" Title", body,
                getPendingIntent(this, MainActivity.class), action, action, action));
        break;

    case NOTI_2:
        Glide.with(this).load(uri != null ? uri : URL1).asBitmap().into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap source, GlideAnimation<? super Bitmap> glideAnimation) {
                //                                float radius = Resources.getSystem().getDisplayMetrics().density * 8;
                //                                Bitmap bitmap = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
                //                                Canvas canvas = new Canvas(bitmap);
                //                                Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
                //                                paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
                //                                RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
                //                                canvas.drawRoundRect(rectF, radius, radius, paint);
                //
                //                                ImageView img = findViewById(R.id.img);
                //                                img.setImageBitmap(bitmap);
                helper.notify(NOTI_ID_2++, helper.buildNotificationImage(" Title", body, source,
                        getPendingIntent(App.getCtx(), MainActivity.class)));
            }
        });

        break;

    case NOTI_3:
        helper.notify(NOTI_ID_3, helper.buildCustomNotificationDefault("  Title", body,
                getPendingIntent(this, MainActivity.class)));
        break;
    }
}

From source file:com.tourmaline.example.ExampleApplication.java

public void initEngine(final boolean automaticMonitoring, final CompletionListener completionListener) {

    //TLKit is a foreground service: here we set what is displayed into the
    // device notification area

    final String NOTIF_CHANNEL_ID = "background-run-notif-channel-id";
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        final NotificationChannel channel = new NotificationChannel(NOTIF_CHANNEL_ID,
                getText(R.string.foreground_notification_content_text), NotificationManager.IMPORTANCE_NONE);
        channel.setShowBadge(false);//from  w  w  w. j a  v a 2s. c om
        if (notificationManager != null) {
            notificationManager.createNotificationChannel(channel);
        }
    }

    final Notification note = new NotificationCompat.Builder(this, NOTIF_CHANNEL_ID)
            .setContentTitle(getText(R.string.app_name))
            .setContentText(getText(R.string.foreground_notification_content_text))
            .setSmallIcon(R.mipmap.ic_foreground_notification).setPriority(NotificationCompat.PRIORITY_MIN)
            .build();

    String hashedUserId = HashId(user);
    Engine.Init(getApplicationContext(), ApiKey, hashedUserId, automaticMonitoring, note, completionListener);

}

From source file:com.google.android.apps.muzei.notifications.NewWallpaperNotificationReceiver.java

static boolean isNewWallpaperNotificationEnabled(@NonNull Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        // On O+ devices, we defer to the system setting
        if (!createNotificationChannel(context)) {
            // Don't post the new wallpaper notification in the case where
            // we've also posted the 'Review your settings' notification
            return false;
        }/*w  w w. j a v  a2  s. co m*/
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager == null) {
            return false;
        }
        NotificationChannel channel = notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL);
        return channel != null && channel.getImportance() != NotificationManager.IMPORTANCE_NONE;
    }
    // Prior to O, we maintain our own preference
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    return sp.getBoolean(PREF_ENABLED, true);
}

From source file:nu.yona.app.utils.AppUtils.java

@TargetApi(Build.VERSION_CODES.O)
public static boolean arePersistentNotificationsEnabled(Context context) {
    if (getPersistentNotificationChannel(context) == null) // Channel will be null on first launch of the application.
    {// w w w .j  a  v a2s . com
        createPersistentNotificationChannel(context);
    }
    return getPersistentNotificationChannel(context)
            .getImportance() != android.app.NotificationManager.IMPORTANCE_NONE;
}

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  www .  j a  v a 2s .  com
            }
        }
        Log.d(TAG, "NotificationsDisabled");

        return false;

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

}

From source file:com.google.android.apps.muzei.notifications.NewWallpaperNotificationReceiver.java

/**
 * Create the notification channel for the New Wallpaper notification
 * @return False only in the case where the user had wallpapers disabled in-app, but has not
 * yet seen the 'Review your notification settings' notification
 *///from  w  w w  .  j  av a  2s.  c  o  m
@RequiresApi(api = Build.VERSION_CODES.O)
static boolean createNotificationChannel(Context context) {
    NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    // On O+ devices, we want to push users to change the system notification setting
    // but we'll use their current value to set the default importance
    int defaultImportance = sp.getBoolean(PREF_ENABLED, true) ? NotificationManager.IMPORTANCE_MIN
            : NotificationManager.IMPORTANCE_NONE;
    if (sp.contains(PREF_ENABLED)) {
        sp.edit().remove(PREF_ENABLED).apply();
        if (defaultImportance == NotificationManager.IMPORTANCE_NONE) {
            // Check to see if there was already a channel and give users an
            // easy way to review their notification settings if they had
            // previously disabled notifications but have not yet disabled
            // the channel
            NotificationChannel existingChannel = notificationManager
                    .getNotificationChannel(NOTIFICATION_CHANNEL);
            if (existingChannel != null
                    && existingChannel.getImportance() != NotificationManager.IMPORTANCE_NONE) {
                // Construct an Intent to get to the notification settings screen
                Intent settingsIntent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
                settingsIntent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
                settingsIntent.putExtra(Settings.EXTRA_CHANNEL_ID,
                        NewWallpaperNotificationReceiver.NOTIFICATION_CHANNEL);
                // Build the notification
                NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
                        NOTIFICATION_CHANNEL).setSmallIcon(R.drawable.ic_stat_muzei)
                                .setColor(ContextCompat.getColor(context, R.color.notification))
                                .setAutoCancel(true)
                                .setContentTitle(context.getText(R.string.notification_settings_moved_title))
                                .setContentText(context.getText(R.string.notification_settings_moved_text))
                                .setContentIntent(PendingIntent.getActivity(context, 0, settingsIntent,
                                        PendingIntent.FLAG_UPDATE_CURRENT))
                                .setStyle(new NotificationCompat.BigTextStyle()
                                        .bigText(context.getText(R.string.notification_settings_moved_text)));
                notificationManager.notify(1, builder.build());
                return false;
            }
        }
    }
    NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL,
            context.getString(R.string.notification_new_wallpaper_channel_name), defaultImportance);
    channel.setShowBadge(false);
    notificationManager.createNotificationChannel(channel);
    return true;
}

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

private static boolean filterNotification(AccountEntity account, Notification notification, Context context) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        //noinspection ConstantConditions
        NotificationChannel channel = notificationManager
                .getNotificationChannel(getChannelId(account, notification));
        return channel.getImportance() > NotificationManager.IMPORTANCE_NONE;
    }/*from  w w w  .  j ava 2  s . co m*/

    switch (notification.getType()) {
    default:
    case MENTION:
        return account.getNotificationsMentioned();
    case FOLLOW:
        return account.getNotificationsFollowed();
    case REBLOG:
        return account.getNotificationsReblogged();
    case FAVOURITE:
        return account.getNotificationsFavorited();
    }
}