Example usage for android.app NotificationManager createNotificationChannel

List of usage examples for android.app NotificationManager createNotificationChannel

Introduction

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

Prototype

public void createNotificationChannel(@NonNull NotificationChannel channel) 

Source Link

Document

Creates a notification channel that notifications can be posted to.

Usage

From source file:org.odk.collect.android.utilities.NotificationUtils.java

public static void createNotificationChannel(Collect collect) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager = collect.getSystemService(NotificationManager.class);

        if (notificationManager != null) {
            notificationManager.createNotificationChannel(
                    new NotificationChannel(CHANNEL_ID, collect.getString(R.string.notification_channel_name),
                            NotificationManager.IMPORTANCE_DEFAULT));
        }//w w  w . ja va 2  s  . c  o m
    }
}

From source file:com.android.contacts.util.ContactsNotificationChannelsUtil.java

public static void createDefaultChannel(Context context) {
    if (!BuildCompat.isAtLeastO()) {
        return;/*from  w  w  w.  jav  a  2 s.  c o  m*/
    }
    final NotificationManager nm = context.getSystemService(NotificationManager.class);
    final NotificationChannel channel = new NotificationChannel(DEFAULT_CHANNEL,
            context.getString(R.string.contacts_default_notification_channel),
            NotificationManager.IMPORTANCE_LOW);
    nm.createNotificationChannel(channel);
}

From source file:org.iota.wallet.helper.NotificationHelper.java

@RequiresApi(api = Build.VERSION_CODES.O)
private static void createNotificationChannel(Context context) {
    NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
    NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL,
            context.getResources().getString(R.string.app_name), NotificationManager.IMPORTANCE_MIN);
    notificationManager.createNotificationChannel(channel);
}

From source file:com.commonsware.android.sawmonitor.SAWDetector.java

static void seeSAW(Context ctxt, String pkg, String operation) {
    if (hasSAW(ctxt, pkg)) {
        Uri pkgUri = Uri.parse("package:" + pkg);
        Intent manage = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);

        manage.setData(pkgUri);/*from w w w .  j  ava2  s.co m*/

        Intent whitelist = new Intent(ctxt, WhitelistReceiver.class);

        whitelist.setData(pkgUri);

        Intent main = new Intent(ctxt, MainActivity.class);

        main.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

        NotificationManager mgr = (NotificationManager) ctxt.getSystemService(Context.NOTIFICATION_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
                && mgr.getNotificationChannel(CHANNEL_WHATEVER) == null) {
            mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever",
                    NotificationManager.IMPORTANCE_DEFAULT));
        }

        NotificationCompat.Builder b = new NotificationCompat.Builder(ctxt, CHANNEL_WHATEVER);
        String text = String.format(ctxt.getString(R.string.msg_requested), operation, pkg);

        b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis())
                .setContentTitle(ctxt.getString(R.string.msg_detected)).setContentText(text)
                .setSmallIcon(android.R.drawable.stat_notify_error)
                .setTicker(ctxt.getString(R.string.msg_detected))
                .setContentIntent(PendingIntent.getActivity(ctxt, 0, manage, PendingIntent.FLAG_UPDATE_CURRENT))
                .addAction(R.drawable.ic_verified_user_24dp, ctxt.getString(R.string.msg_whitelist),
                        PendingIntent.getBroadcast(ctxt, 0, whitelist, 0))
                .addAction(R.drawable.ic_settings_24dp, ctxt.getString(R.string.msg_settings),
                        PendingIntent.getActivity(ctxt, 0, main, 0));

        mgr.notify(NOTIFY_ID, b.build());
    }
}

From source file:com.android.tv.tuner.setup.TunerSetupActivity.java

private static void sendNotificationInternal(Context context, String contentTitle, String contentText) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.createNotificationChannel(new NotificationChannel(TUNER_SET_UP_NOTIFICATION_CHANNEL_ID,
            context.getResources().getString(R.string.ut_setup_notification_channel_name),
            NotificationManager.IMPORTANCE_HIGH));
    Notification notification = new Notification.Builder(context, TUNER_SET_UP_NOTIFICATION_CHANNEL_ID)
            .setContentTitle(contentTitle).setContentText(contentText)
            .setSmallIcon(//from w  w w .j av a  2 s  .co m
                    context.getResources().getIdentifier(TAG_ICON, TAG_DRAWABLE, context.getPackageName()))
            .setContentIntent(createPendingIntentForSetupActivity(context))
            .setVisibility(Notification.VISIBILITY_PUBLIC).extend(new Notification.TvExtender()).build();
    notificationManager.notify(NOTIFY_TAG, NOTIFY_ID, notification);
}

From source file:github.popeen.dsub.util.Notifications.java

@TargetApi(Build.VERSION_CODES.O)
private static NotificationChannel getPlayingNotificationChannel(Context context) {
    if (playingChannel == null) {
        playingChannel = new NotificationChannel("now-playing-channel", "Now Playing",
                NotificationManager.IMPORTANCE_LOW);
        playingChannel.setDescription("Now playing notification");

        NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(playingChannel);
    }//from   ww  w.j  a  v  a  2 s  . c  om

    return playingChannel;
}

From source file:github.popeen.dsub.util.Notifications.java

@TargetApi(Build.VERSION_CODES.O)
private static NotificationChannel getDownloadingNotificationChannel(Context context) {
    if (downloadingChannel == null) {
        downloadingChannel = new NotificationChannel("downloading-channel", "Downloading Notification",
                NotificationManager.IMPORTANCE_LOW);
        downloadingChannel.setDescription("Ongoing downloading notification to keep the service alive");

        NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(downloadingChannel);
    }/* w  ww .jav a 2s . co  m*/

    return downloadingChannel;
}

From source file:github.popeen.dsub.util.Notifications.java

@TargetApi(Build.VERSION_CODES.O)
private static NotificationChannel getSyncNotificationChannel(Context context) {
    if (syncChannel == null) {
        syncChannel = new NotificationChannel("sync-channel", "Sync Notifications",
                NotificationManager.IMPORTANCE_MIN);
        syncChannel.setDescription("Sync notifications");

        NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(syncChannel);
    }//  w  w  w.  j  av a 2s . com

    return syncChannel;
}

From source file:com.none.tom.simplerssreader.service.FeedUpdateBackgroundService.java

@SuppressWarnings({ "ConstantConditions", "deprecation" })
private static void showNotification(final Context context, final List<String> payload) {
    final NotificationManager manager = context.getSystemService(NotificationManager.class);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);

        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        channel.setBypassDnd(false);/*from   www  .  java2  s . c  om*/
        channel.enableLights(true);
        channel.setShowBadge(true);
        channel.enableVibration(true);

        manager.createNotificationChannel(channel);
    }

    final PendingIntent intent = PendingIntent.getActivity(context, 0,
            new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
            PendingIntent.FLAG_UPDATE_CURRENT);

    final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle()
            .setBigContentTitle(context.getString(R.string.notification_title_big));

    final int size = payload.size();

    for (int i = 0; i < size; i++) {
        style.addLine(payload.get(i));
    }

    manager.notify(ID_NOTIFICATION, new NotificationCompat.Builder(context)
            .setChannelId(NOTIFICATION_CHANNEL_ID).setSmallIcon(R.drawable.ic_rss_feed_white_24dp)
            .setContentTitle(context.getString(R.string.notification_title))
            .setContentText(context.getString(R.string.notification_text)).setContentIntent(intent)
            .setStyle(style).setWhen(System.currentTimeMillis()).setAutoCancel(true).setShowWhen(true).build());
}

From source file:cl.chihau.holaauto.MyMessagingService.java

public void mostrarNotificacion(int id, Notification notificacion) {
    NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String name = "my channel";
        String description = "channel description";
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel channel = new NotificationChannel(canal, name, importance);
        channel.setDescription(description);

        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        manager.createNotificationChannel(channel);
    }//  w w  w.j  ava  2 s  .c om

    mNotificationManager.notify(id, notificacion);

}