Example usage for android.app NotificationChannel NotificationChannel

List of usage examples for android.app NotificationChannel NotificationChannel

Introduction

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

Prototype

public NotificationChannel(String id, CharSequence name, @Importance int importance) 

Source Link

Document

Creates a notification channel.

Usage

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

public static void createDefaultChannel(Context context) {
    if (!BuildCompat.isAtLeastO()) {
        return;/* w  ww .  j a v  a2  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.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));
        }/*from   ww  w  .  ja  v a 2 s.c  o m*/
    }
}

From source file:com.google.android.gms.location.sample.backgroundlocationupdates.LocationResultHelper.java

LocationResultHelper(Context context, List<Location> locations) {
    mContext = context;/*from   ww w. ja v a  2  s  . c  om*/
    mLocations = locations;

    NotificationChannel channel = new NotificationChannel(PRIMARY_CHANNEL,
            context.getString(R.string.default_channel), NotificationManager.IMPORTANCE_DEFAULT);
    channel.setLightColor(Color.GREEN);
    channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    getNotificationManager().createNotificationChannel(channel);
}

From source file:com.ubergeek42.WeechatAndroid.service.Notificator.java

@MainThread
public static void init(Context c) {
    context = c.getApplicationContext();
    manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
        return;/*  ww w. j ava  2s.  c o  m*/

    NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_CONNECTION_STATUS,
            context.getString(R.string.notification_channel_connection_status),
            NotificationManager.IMPORTANCE_MIN);
    channel.setShowBadge(false);
    manager.createNotificationChannel(channel);

    channel = new NotificationChannel(NOTIFICATION_CHANNEL_HOTLIST,
            context.getString(R.string.notification_channel_hotlist), NotificationManager.IMPORTANCE_DEFAULT);
    manager.createNotificationChannel(channel);
}

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 www  .  ja v  a 2 s  .com*/
}

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.  ja  v  a 2s . c  om

        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.davidmiguel.gobees.utils.NotificationsHelper.java

@RequiresApi(Build.VERSION_CODES.O)
private void createMonitoringChannel() {
    NotificationChannel channel = new NotificationChannel(MONITORING_CHANNEL,
            getString(R.string.not_channel_monitoring), NotificationManager.IMPORTANCE_LOW);
    channel.setDescription(getString(R.string.not_channel_monitoring_desc));
    channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    channel.setShowBadge(false);/*from   w w w  .j av  a 2 s  .com*/
    channel.enableLights(false);
    getManager().createNotificationChannel(channel);
}

From source file:com.cryart.sabbathschool.misc.SSReminderService.java

@Override
public boolean onStartJob(JobParameters job) {
    Context context = getBaseContext();
    SSReminder.scheduleAlarms(context);/*  w  w  w.  j  av  a  2 s.co  m*/
    try {
        String channelId = "ss_notification_channel";
        String channelName = getString(R.string.app_name);

        NotificationManager _SSNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel mChannel = new NotificationChannel(channelId, channelName, importance);
            _SSNotificationManager.createNotificationChannel(mChannel);
        }
        Intent _SSContentIntent = new Intent(context, SSSplashActivity.class);

        Intent _SSShareIntent = new Intent();

        _SSContentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        _SSShareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        _SSShareIntent.setAction(Intent.ACTION_SEND);
        _SSShareIntent.putExtra(Intent.EXTRA_TEXT, "");

        _SSShareIntent.setType("*/*");

        PendingIntent _SSPendingContentIntent = PendingIntent.getActivity(context, 0, _SSContentIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        PendingIntent _SSPendingShareIntent = PendingIntent.getActivity(context, 0,
                Intent.createChooser(_SSShareIntent, context.getString(R.string.ss_share)),
                PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder _SSNotificationBuilder = new NotificationCompat.Builder(context,
                "ss_notification_channel").setSmallIcon(R.mipmap.ic_stat_notification)
                        .setContentTitle(context.getString(R.string.ss_app_name))
                        .setColor(Color.parseColor(SSColorTheme.getInstance().getColorPrimary()))
                        .addAction(0, context.getString(R.string.ss_menu_read_now), _SSPendingContentIntent)
                        .addAction(0, context.getString(R.string.ss_share), _SSPendingShareIntent)
                        .setAutoCancel(true).setVibrate(new long[] { 1000, 1000 })
                        .setContentIntent(_SSPendingContentIntent)
                        .setContentText(context.getString(R.string.ss_settings_reminder_text));

        _SSNotificationManager.notify(1, _SSNotificationBuilder.build());
    } catch (Exception e) {
        Crashlytics.log(e.getMessage());
    }

    return false; // Answers the question: "Is there still work going on?"
}

From source file:com.commonsware.android.bluetooth.rxecho.ShoutingEchoService.java

@Override
public void onCreate() {
    super.onCreate();

    rxBluetooth = new RxBluetooth(getApplicationContext());
    acceptConnections();//www . ja  va  2 s .com

    NotificationManager mgr = (NotificationManager) getSystemService(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));
    }

    startForeground(1338, buildForegroundNotification());

    STATUS.postValue(Status.IS_RUNNING);
}

From source file:org.deviceconnect.android.deviceplugin.host.recorder.AbstractPreviewServerProvider.java

/**
 * Notification??.//from   w  ww .ja va  2 s .c  om
 */
public void sendNotification() {
    PendingIntent contentIntent = createPendingIntent();
    Notification notification = createNotification(contentIntent, null);
    NotificationManager manager = (NotificationManager) mContext.getSystemService(Service.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String channelId = mContext.getResources().getString(R.string.overlay_preview_channel_id);
        NotificationChannel channel = new NotificationChannel(channelId,
                mContext.getResources().getString(R.string.overlay_preview_content_title),
                NotificationManager.IMPORTANCE_LOW);
        channel.setDescription(mContext.getResources().getString(R.string.overlay_preview_content_message));
        manager.createNotificationChannel(channel);
        notification = createNotification(contentIntent, channelId);
    }
    manager.notify(getId(), getNotificationId(), notification);
}