List of usage examples for android.app NotificationChannel setDescription
public void setDescription(String description)
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.ja va2 s . co m }
From source file:org.deviceconnect.android.deviceplugin.host.recorder.AbstractPreviewServerProvider.java
/** * Notification??.//from www .java 2 s. c o m */ 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); }
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 ww.ja v a2s . com } 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:arun.com.chromer.appdetect.AppDetectService.java
private void initChannels() { if (Utils.ANDROID_OREO) { NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "App Detection Service", NotificationManager.IMPORTANCE_MIN); channel.setDescription(getString(R.string.app_detection_notification_channel_description)); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(channel); }/*from w ww.ja v a 2 s . c o m*/ }
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 w w .j av a 2 s. c om*/ 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); } }
From source file:com.scooter1556.sms.android.manager.MediaNotificationManager.java
/** * Creates Notification Channel. This is required in Android O+ to display notifications. *//*from ww w . ja v a2s. c om*/ private void createNotificationChannel() { if (notificationManager.getNotificationChannel(CHANNEL_ID) == null) { NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, mediaService.getString(R.string.notification_channel), NotificationManager.IMPORTANCE_LOW); notificationChannel.setDescription(mediaService.getString(R.string.notification_channel_description)); notificationManager.createNotificationChannel(notificationChannel); } }
From source file:arun.com.chromer.webheads.WebHeadService.java
@NonNull @Override// ww w . j a va 2 s .c om public Notification getNotification() { if (Utils.ANDROID_OREO) { final NotificationChannel channel = new NotificationChannel(WebHeadService.class.getName(), getString(R.string.web_heads_service), NotificationManager.IMPORTANCE_MIN); channel.setDescription(getString(R.string.app_detection_notification_channel_description)); final NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); if (notificationManager != null) { notificationManager.createNotificationChannel(channel); } } final PendingIntent contentIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_STOP_WEBHEAD_SERVICE), FLAG_UPDATE_CURRENT); final PendingIntent contextActivity = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_OPEN_CONTEXT_ACTIVITY), FLAG_UPDATE_CURRENT); final PendingIntent newTab = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_OPEN_NEW_TAB), FLAG_UPDATE_CURRENT); Notification notification = new NotificationCompat.Builder(this, WebHeadService.class.getName()) .setSmallIcon(R.drawable.ic_chromer_notification).setPriority(PRIORITY_MIN) .setContentText(getString(R.string.tap_close_all)) .setColor(ContextCompat.getColor(this, R.color.colorPrimary)) .addAction(R.drawable.ic_add, getText(R.string.open_new_tab), newTab) .addAction(R.drawable.ic_list, getText(R.string.manage), contextActivity) .setContentTitle(getString(R.string.web_heads_service)).setContentIntent(contentIntent) .setAutoCancel(false).setLocalOnly(true).build(); notification.flags |= Notification.FLAG_FOREGROUND_SERVICE; return notification; }
From source file:im.vector.notifications.NotificationUtils.java
/** * Add a notification groups.//from w ww .ja v a 2s. c om * * @param context the context */ @SuppressLint("NewApi") public static void addNotificationChannels(Context context) { if (Build.VERSION.SDK_INT < 26) { return; } if (null == NOISY_NOTIFICATION_CHANNEL_NAME) { NOISY_NOTIFICATION_CHANNEL_NAME = context.getString(R.string.notification_noisy_notifications); } if (null == SILENT_NOTIFICATION_CHANNEL_NAME) { SILENT_NOTIFICATION_CHANNEL_NAME = context.getString(R.string.notification_silent_notifications); } if (null == CALL_NOTIFICATION_CHANNEL_NAME) { CALL_NOTIFICATION_CHANNEL_NAME = context.getString(R.string.call); } if (null == LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_NAME) { LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_NAME = context .getString(R.string.notification_listen_for_events); } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // A notification channel cannot be updated : // it must be deleted and created with another channel id if ((null == NOISY_NOTIFICATION_CHANNEL_ID)) { List<NotificationChannel> channels = notificationManager.getNotificationChannels(); for (NotificationChannel channel : channels) { if (channel.getId().startsWith(NOISY_NOTIFICATION_CHANNEL_ID_BASE)) { NOISY_NOTIFICATION_CHANNEL_ID = channel.getId(); } } } if (null != NOISY_NOTIFICATION_CHANNEL_ID) { NotificationChannel channel = notificationManager.getNotificationChannel(NOISY_NOTIFICATION_CHANNEL_ID); Uri notificationSound = channel.getSound(); Uri expectedSound = PreferencesManager.getNotificationRingTone(context); // the notification sound has been updated // need to delete it, to create a new one // else the sound won't be updated if (((null == notificationSound) ^ (null == expectedSound)) || ((null != notificationSound) && !TextUtils.equals(notificationSound.toString(), expectedSound.toString()))) { notificationManager.deleteNotificationChannel(NOISY_NOTIFICATION_CHANNEL_ID); NOISY_NOTIFICATION_CHANNEL_ID = null; } } if (null == NOISY_NOTIFICATION_CHANNEL_ID) { NOISY_NOTIFICATION_CHANNEL_ID = NOISY_NOTIFICATION_CHANNEL_ID_BASE + System.currentTimeMillis(); NotificationChannel channel = new NotificationChannel(NOISY_NOTIFICATION_CHANNEL_ID, NOISY_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(NOISY_NOTIFICATION_CHANNEL_NAME); channel.setSound(PreferencesManager.getNotificationRingTone(context), null); channel.enableVibration(true); notificationManager.createNotificationChannel(channel); } if (null == notificationManager.getNotificationChannel(SILENT_NOTIFICATION_CHANNEL_NAME)) { NotificationChannel channel = new NotificationChannel(SILENT_NOTIFICATION_CHANNEL_ID, SILENT_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(SILENT_NOTIFICATION_CHANNEL_NAME); channel.setSound(null, null); notificationManager.createNotificationChannel(channel); } if (null == notificationManager.getNotificationChannel(LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_ID)) { NotificationChannel channel = new NotificationChannel(LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_ID, LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_MIN); channel.setDescription(LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_NAME); channel.setSound(null, null); notificationManager.createNotificationChannel(channel); } if (null == notificationManager.getNotificationChannel(CALL_NOTIFICATION_CHANNEL_ID)) { NotificationChannel channel = new NotificationChannel(CALL_NOTIFICATION_CHANNEL_ID, CALL_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(CALL_NOTIFICATION_CHANNEL_NAME); channel.setSound(null, null); notificationManager.createNotificationChannel(channel); } }
From source file:com.owncloud.android.media.MediaService.java
/** * Initialize a service instance/*from w w w .j a va 2 s . co m*/ * * {@inheritDoc} */ @Override public void onCreate() { super.onCreate(); Log_OC.d(TAG, "Creating ownCloud media service"); mWifiLock = ((WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, MEDIA_WIFI_LOCK_TAG); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Configure notification channel if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel mNotificationChannel; // The user-visible name of the channel. CharSequence name = getString(R.string.media_service_notification_channel_name); // The user-visible description of the channel. String description = getString(R.string.media_service_notification_channel_description); // Set importance low: show the notification everywhere but with no sound int importance = NotificationManager.IMPORTANCE_LOW; mNotificationChannel = new NotificationChannel(MEDIA_SERVICE_NOTIFICATION_CHANNEL_ID, name, importance); // Configure the notification channel. mNotificationChannel.setDescription(description); mNotificationManager.createNotificationChannel(mNotificationChannel); } mNotificationBuilder = new NotificationCompat.Builder(this); mNotificationBuilder.setColor(this.getResources().getColor(R.color.primary)); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); mBinder = new MediaServiceBinder(this); // add AccountsUpdatedListener mAccountManager = AccountManager.get(this); mAccountManager.addOnAccountsUpdatedListener(new OnAccountsUpdateListener() { @Override public void onAccountsUpdated(Account[] accounts) { // stop playback if account of the played media files was removed if (mAccount != null && !AccountUtils.exists(mAccount.name, MediaService.this)) { processStopRequest(false); } } }, null, false); }
From source file:org.pocketworkstation.pckeyboard.LatinIME.java
private void createNotificationChannel() { // Create the NotificationChannel, but only on API 26+ because // the NotificationChannel class is new and not in the support library if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CharSequence name = getString(R.string.notification_channel_name); String description = getString(R.string.notification_channel_description); int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance); channel.setDescription(description); // Register the channel with the system; you can't change the importance // or other notification behaviors after this NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); }//from www . j av a 2 s . c o m }