List of usage examples for android.app NotificationChannel NotificationChannel
public NotificationChannel(String id, CharSequence name, @Importance int importance)
From source file:com.commonsware.android.service.lifecycle.DemoService.java
@TargetApi(Build.VERSION_CODES.O) private void initChannels() { NotificationChannel channel = new NotificationChannel(CHANNEL_MIN, getString(R.string.channel_min), NotificationManager.IMPORTANCE_MIN); mgr.createNotificationChannel(channel); channel = new NotificationChannel(CHANNEL_LOW, getString(R.string.channel_low), NotificationManager.IMPORTANCE_LOW); mgr.createNotificationChannel(channel); }
From source file:kr.ds.mymunsang.MyFirebaseMessagingService.java
private void sendNotification(String message, Bitmap bitmap) { Intent intent = new Intent(this, MainActivity2.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); String channelId = getString(R.string.channel_message_id); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId) .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.icon) .setContentTitle(getString(R.string.app_name)).setContentText(message).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); if (bitmap != null) { NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle(); style.setBigContentTitle(getString(R.string.app_name)); style.setSummaryText(message);//from w ww .ja va 2 s .c o m style.bigPicture(bitmap); notificationBuilder.setStyle(style); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Since android Oreo notification channel is needed. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, getString(R.string.channel_message_id), NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(getString(R.string.channel_message)); notificationManager.createNotificationChannel(channel); } notificationManager.notify(0, notificationBuilder.build()); }
From source file:kr.ds.say.MyFirebaseMessagingService.java
private void sendNotification(String message, Bitmap bitmap) { Intent intent = new Intent(this, IntroActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); String channelId = getString(R.string.channel_message_id); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId) .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.mipmap.icon) .setContentTitle(getString(R.string.app_name)).setContentText(message).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); if (bitmap != null) { NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle(); style.setBigContentTitle(getString(R.string.app_name)); style.setSummaryText(message);//from www .j a v a2s .com style.bigPicture(bitmap); notificationBuilder.setStyle(style); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Since android Oreo notification channel is needed. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, getString(R.string.channel_message_id), NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(getString(R.string.channel_message)); notificationManager.createNotificationChannel(channel); } notificationManager.notify(UniqueID.getRandomNumber(1000), notificationBuilder.build()); }
From source file:com.clanofthecloud.cotcpushnotifications.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from w w w. ja v a 2 s .c o m*/ */ private void sendNotification(String message) { Activity currentAct = UnityPlayer.currentActivity; Class activityToOpen = currentAct != null ? currentAct.getClass() : UnityPlayerActivity.class; Intent intent = new Intent(this, activityToOpen); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); ApplicationInfo ai = null; try { ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); int notificationIcon = ai.metaData.getInt("cotc.GcmNotificationIcon", -1); if (notificationIcon == -1) { Log.e(TAG, "!!!!!!!!! cotc.GcmNotificationIcon not configured in manifest, push notifications won't work !!!!!!!!!"); return; } int notificationLargeIcon = ai.metaData.getInt("cotc.GcmNotificationLargeIcon", -1); if (notificationLargeIcon == -1) { Log.e(TAG, "There is no large icon for push notifs, will only use default icon"); return; } String pushNotifName = ai.metaData.getString("cotc.GcmNotificationTitle"); if (pushNotifName == null) { Log.e(TAG, "!!!!!!!!! cotc.GcmNotificationTitle not configured in manifest, push notifications won't work !!!!!!!!!"); return; } if (notifManager == null) notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notificationBuilder; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { int importance = NotificationManager.IMPORTANCE_HIGH; NotificationChannel channel = new NotificationChannel("CotC Channel", "CotC Channel", importance); channel.setDescription("CotC Channel"); notifManager.createNotificationChannel(channel); notificationBuilder = new NotificationCompat.Builder(this, "CotC Channel"); } else notificationBuilder = new NotificationCompat.Builder(this); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); notificationBuilder.setSmallIcon(notificationIcon).setContentTitle(pushNotifName) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent).setPriority(Notification.PRIORITY_HIGH); if (notificationLargeIcon != -1) notificationBuilder.setLargeIcon( BitmapFactory.decodeResource(currentAct.getResources(), notificationLargeIcon)); notifManager.notify(0 /* ID of notification */, notificationBuilder.build()); } catch (Exception e) { Log.w(TAG, "Failed to handle push notification", e); } }
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 ww .j ava 2 s .c o m*/ 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.commonsware.android.notify.channel.MainActivity.java
private void initContentChannel() { NotificationChannel channel = new NotificationChannel(CHANNEL_CONTENT, getString(R.string.channel_name_content), NotificationManager.IMPORTANCE_LOW); channel.setGroup(GROUP_UPDATES);//from w w w. j a v a 2s . co m mgr.createNotificationChannel(channel); }
From source file:kr.ds.mymunsang.MyFirebaseMessagingService.java
private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity2.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); String channelId = getString(R.string.channel_message_id); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId) .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.icon) .setContentTitle(getString(R.string.app_name)).setContentText(message).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Since android Oreo notification channel is needed. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, getString(R.string.channel_message_id), NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(getString(R.string.channel_message)); notificationManager.createNotificationChannel(channel); }/*from ww w .j a va 2s .c o m*/ notificationManager.notify(0, notificationBuilder.build()); }
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 w w . ja va2 s . co m*/ }
From source file:com.commonsware.android.notify.channel.MainActivity.java
private void initBattleChannel() { NotificationChannel channel = new NotificationChannel(CHANNEL_BATTLE, getString(R.string.channel_name_battle), NotificationManager.IMPORTANCE_HIGH); channel.setGroup(GROUP_UPDATES);//from w ww . j av a 2 s . c o m channel.setShowBadge(true); mgr.createNotificationChannel(channel); }
From source file:com.commonsware.android.notify.channel.MainActivity.java
private void initCoinsChannel() { NotificationChannel channel = new NotificationChannel(CHANNEL_COINS, getString(R.string.channel_name_coins), NotificationManager.IMPORTANCE_DEFAULT); channel.setGroup(GROUP_PROMO);/* www.ja v a 2 s. c om*/ mgr.createNotificationChannel(channel); }