List of usage examples for android.app NotificationManager IMPORTANCE_DEFAULT
int IMPORTANCE_DEFAULT
To view the source code for android.app NotificationManager IMPORTANCE_DEFAULT.
Click Source Link
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); }// www . j ava2s .co m notificationManager.notify(0, notificationBuilder.build()); }
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);//from www. ja va2 s .c om mgr.createNotificationChannel(channel); }
From source file:kr.ds.say.MyFirebaseMessagingService.java
private void sendNotification(String message) { 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); 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); }//ww w .j a v a 2 s.c o m notificationManager.notify(UniqueID.getRandomNumber(1000), notificationBuilder.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); }/*from www .j a v a 2s .co m*/ mNotificationManager.notify(id, notificacion); }
From source file:com.instify.android.services.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *///from ww w . j a v a 2 s . c o m private void sendNotification(String messageBody) { Intent intent = new Intent(this, MainActivity.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.default_notification_channel_id); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId) .setSmallIcon(R.drawable.ic_notification_white).setContentTitle("FCM Message") .setContentText(messageBody).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, "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); } notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:im.vector.notifications.NotificationUtils.java
/** * Add a notification groups.//from w ww. j ava2 s. c o m * * @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.peptrack.gps.locationupdatesforegroundservice.LocationUpdatesService.java
@Override public void onCreate() { mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this); mLocationCallback = new LocationCallback() { @Override//from w w w.ja va2 s . co m public void onLocationResult(LocationResult locationResult) { super.onLocationResult(locationResult); onNewLocation(locationResult.getLastLocation()); } }; createLocationRequest(); getLastLocation(); HandlerThread handlerThread = new HandlerThread(TAG); handlerThread.start(); mServiceHandler = new Handler(handlerThread.getLooper()); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Android O requires a Notification Channel. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CharSequence name = getString(R.string.app_name); // Create the channel for the notification NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_DEFAULT); // Set the Notification Channel for the Notification Manager. mNotificationManager.createNotificationChannel(mChannel); } }
From source file:com.shoppingspree.shoppingspree.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from w w w.ja v a2 s . co m*/ private void sendNotification(String messageBody) { Intent intent = new Intent(this, MainActivity.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.default_notification_channel_id); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("Buy Through Shopping Spree") .setContentText(messageBody).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, "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); } notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.google.firebase.quickstart.fcm.java.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from www . j a v a 2 s . c om*/ private void sendNotification(String messageBody) { Intent intent = new Intent(this, MainActivity.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.default_notification_channel_id); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle(getString(R.string.fcm_message)) .setContentText(messageBody).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, "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); } notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:sachinjain024.practicebook.io.firebase_android_notifications.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param notification FCM notification received. *//*from ww w . j a v a 2 s. com*/ private void sendNotification(RemoteMessage.Notification notification) { String title = notification.getTitle(); String messageBody = notification.getBody(); Intent intent = new Intent(this, MainActivity.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.default_notification_channel_id); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId) .setSmallIcon(R.drawable.ic_launcher_foreground) .setBadgeIconType(R.drawable.common_google_signin_btn_icon_light) .setColor(getResources().getColor(R.color.colorAccent)).setContentTitle(title + "Title Updated") .setContentText(messageBody).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, "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); } notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }