Example usage for android.app NotificationChannel setShowBadge

List of usage examples for android.app NotificationChannel setShowBadge

Introduction

In this page you can find the example usage for android.app NotificationChannel setShowBadge.

Prototype

public void setShowBadge(boolean showBadge) 

Source Link

Document

Sets whether notifications posted to this channel can appear as application icon badges in a Launcher.

Usage

From source file:com.sxt.chat.utils.NotificationHelper.java

/**
 * ?/*from   w  ww. ja  va2  s  . c  om*/
 * <p>
 * note : notify() ? ???,?? so, Create?
 */
public NotificationHelper(Context ctx) {
    super(ctx);
    context = ctx;
    soundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notify_message);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        AudioAttributes att = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION)
                .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH).build();
        NotificationChannel channel = new NotificationChannel(DEFAULT_CHANNEL, "Channel",
                NotificationManager.IMPORTANCE_HIGH);
        channel.setSound(soundUri, att);
        channel.setLightColor(Color.YELLOW);
        channel.setShowBadge(true);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        getManager().createNotificationChannel(channel);

        NotificationChannel chanCustom = new NotificationChannel(CUSTOM_NOTIFY_CHANNEL, "Custom Layout Channel",
                NotificationManager.IMPORTANCE_HIGH);
        channel.setSound(soundUri, att);
        chanCustom.setLightColor(Color.RED);
        chanCustom.setShowBadge(true);
        chanCustom.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        getManager().createNotificationChannel(chanCustom);
    }
}

From source file:org.mozilla.focus.session.SessionNotificationService.java

public void createNotificationChannelIfNeeded() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        // Notification channels are only available on Android O or higher.
        return;// w w w.j  a  v a  2 s .c o  m
    }

    final NotificationManager notificationManager = getSystemService(NotificationManager.class);
    if (notificationManager == null) {
        return;
    }

    final String notificationChannelName = getString(R.string.notification_browsing_session_channel_name);
    final String notificationChannelDescription = getString(
            R.string.notification_browsing_session_channel_description, getString(R.string.app_name));

    final NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
            notificationChannelName, NotificationManager.IMPORTANCE_MIN);
    channel.setImportance(NotificationManager.IMPORTANCE_LOW);
    channel.setDescription(notificationChannelDescription);
    channel.enableLights(false);
    channel.enableVibration(false);
    channel.setShowBadge(true);

    notificationManager.createNotificationChannel(channel);
}

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);
        if (notificationManager != null) {
            notificationManager.createNotificationChannel(channel);
        }/*from w w  w . jav a 2 s  .c o m*/
    }

    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:chat.viska.android.Application.java

private void initializeNotificationChannels() {
    if (Build.VERSION.SDK_INT >= 26) {
        final NotificationManager manager = getSystemService(NotificationManager.class);

        final NotificationChannel systemChannel = new NotificationChannel(KEY_NOTIF_CHANNEL_SYSTEM,
                getString(R.string.title_notif_channel_system), NotificationManager.IMPORTANCE_LOW);
        systemChannel.setDescription(getString(R.string.desc_notif_channel_system));
        systemChannel.enableVibration(false);
        systemChannel.enableLights(false);
        systemChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        systemChannel.setShowBadge(false);
        manager.createNotificationChannel(systemChannel);

        final NotificationChannel messagingChannel = new NotificationChannel(KEY_NOTIF_CHANNEL_MESSAGES,
                getString(R.string.title_notif_channel_messaging), NotificationManager.IMPORTANCE_HIGH);
        systemChannel.setDescription(getString(R.string.desc_notif_channel_messaging));
        systemChannel.enableVibration(true);
        systemChannel.enableLights(true);
        systemChannel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
        systemChannel.setShowBadge(true);
        manager.createNotificationChannel(messagingChannel);
    }//from  w w w.  j  av  a 2  s  .c om
}

From source file:com.giovanniterlingen.windesheim.controllers.NotificationController.java

public void initNotificationChannels() {
    if (android.os.Build.VERSION.SDK_INT >= 26) {
        NotificationChannel pushChannel = new NotificationChannel(PUSH_NOTIFICATION_CHANNEL,
                ApplicationLoader.applicationContext.getResources().getString(R.string.push_notification),
                NotificationManager.IMPORTANCE_HIGH);

        pushChannel.setDescription(ApplicationLoader.applicationContext.getResources()
                .getString(R.string.push_notification_description));
        pushChannel.enableLights(true);/*  w  ww . j  a v  a2 s .  co m*/
        pushChannel.enableVibration(true);
        pushChannel.setShowBadge(true);
        pushChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

        NotificationChannel persistentChannel = new NotificationChannel(PERSISTENT_NOTIFICATION_CHANNEL,
                ApplicationLoader.applicationContext.getResources().getString(R.string.persistent_notification),
                NotificationManager.IMPORTANCE_MIN);

        persistentChannel.setDescription(ApplicationLoader.applicationContext.getResources()
                .getString(R.string.persistent_notification_description));
        persistentChannel.enableLights(false);
        persistentChannel.enableVibration(false);
        persistentChannel.setShowBadge(false);
        persistentChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

        NotificationChannel serviceChannel = new NotificationChannel(SERVICE_NOTIFICATION_CHANNEL,
                ApplicationLoader.applicationContext.getResources().getString(R.string.service_notification),
                NotificationManager.IMPORTANCE_MIN);

        serviceChannel.setDescription(ApplicationLoader.applicationContext.getResources()
                .getString(R.string.service_notification_description));
        serviceChannel.enableLights(false);
        serviceChannel.enableVibration(false);
        serviceChannel.setShowBadge(false);
        serviceChannel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);

        NotificationManager mManager = (NotificationManager) ApplicationLoader.applicationContext
                .getSystemService(Context.NOTIFICATION_SERVICE);

        mManager.createNotificationChannel(pushChannel);
        mManager.createNotificationChannel(persistentChannel);
        mManager.createNotificationChannel(serviceChannel);
    }
}