List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:com.mjhram.ttaxi.gcm_client.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.// w ww . ja v a 2 s . c o m */ private void sendNotification(String message) { Intent intent = new Intent(this, GpsMainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.circle_green).setContentTitle(getString(R.string.gcmClientGcmMsg)) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.bosco.noticeboard.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param note Notice received from server. *//*from ww w.j a v a2 s . c om*/ private void sendNotification(Notice note) { Intent intent = new Intent(this, NoticeActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("Notice", note); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(note.subject).setSmallIcon(R.drawable.normal_bell).setContentText(note.content) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); if (note.priority == 1) { notificationBuilder.setColor(getResources().getColor(R.color.icon_normal)); } else if (note.priority == 2) { notificationBuilder.setColor(getResources().getColor(R.color.icon_important)); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.example.kyle.weatherforecast.MainActivity.java
private void postAlert(int i) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle("Weather Alert!").setContentText(WeatherData.outlookArray[i]) .setSmallIcon(R.drawable.small_icon) .setLargeIcon(BitmapFactory.decodeResource(getResources(), WeatherData.symbolArray[i])) .setAutoCancel(true).setTicker("Wrap up warm!") // Heads-up and lock screen notifications .setVisibility(Notification.VISIBILITY_PUBLIC).setPriority(Notification.PRIORITY_HIGH) .setVibrate(new long[] { 100, 100, 100, 200, 200 }).setVibrate(new long[] { 0 }) .setCategory(Notification.CATEGORY_ALARM); NotificationCompat.BigPictureStyle bigStyle = new NotificationCompat.BigPictureStyle(); bigStyle.bigPicture(BitmapFactory.decodeResource(getResources(), R.drawable.snow_scene)); builder.setStyle(bigStyle);/*from ww w .j a v a 2 s . c om*/ Intent intent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class).addNextIntent(intent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId, builder.build()); notificationId++; Log.d(DEBUG_TAG, "ID: " + notificationId); }
From source file:com.andrada.sitracker.tasks.receivers.UpdateStatusNotificationReceiver.java
private void sendNotification(int number, List<String> updatedAuthorNames, @NotNull Context context) { NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); int maxLines = 4; if (updatedAuthorNames.size() < maxLines) { maxLines = updatedAuthorNames.size(); }//from ww w .j a v a2 s . com for (int i = 0; i < maxLines; i++) { inboxStyle.addLine(updatedAuthorNames.get(i)); } if (updatedAuthorNames.size() > 4) { inboxStyle.setSummaryText( context.getString(R.string.notification_more_summary, updatedAuthorNames.size() - 4)); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.notification) .setContentTitle(context.getResources().getString(R.string.notification_title)) .setContentText(context.getResources().getQuantityString(R.plurals.authors_updated, number, number)) .setAutoCancel(true).setOnlyAlertOnce(true) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND).setNumber(number) .setStyle(inboxStyle); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, HomeActivity_.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(HomeActivity_.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(UPDATE_SUCCESS_NOTIFICATION_ID, mBuilder.build()); }
From source file:com.begentgroup.miniproject.gcm.MyGcmListenerService.java
private void sendNotification(ChatMessage m) { Intent intent = new Intent(this, SplashActivity.class); intent.putExtra(ChatActivity.EXTRA_USER, m.getSender()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setTicker("Chat Message") .setContentTitle(m.getSender().getUserName()).setContentText(m.getMessage()).setAutoCancel(true) .setDefaults(NotificationCompat.DEFAULT_ALL).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:kaist.cs492c_2015.washerbrowser.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from w w w .j a v a 2 s . co m */ private void sendNotification(String message) { 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); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("Find available washer") .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }).setSmallIcon(R.drawable.washer_green) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); launchPopupActivity(this, message); }
From source file:com.begentgroup.miniproject.gcm.MyGcmListenerService.java
private void sendNotification(String message) { 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); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setTicker("GCM Message").setContentTitle("GCM Message") .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.android.anton.pushnotificationwithgcm.GCMUtil.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./* w w w . j a v a 2s. co m*/ */ private void sendNotification(String message) { 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); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_notification).setContentTitle("Live Document Translator") .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); // int notificationCount = getSharedPreferences("Notification", MODE_PRIVATE).getInt("Count", 0); // notificationCount ++; // SharedPreferences.Editor editor = this.getSharedPreferences("Notification", MODE_PRIVATE).edit(); // editor.putInt("Count", notificationCount); // editor.commit(); // // boolean success = ShortcutBadger.applyCount(getApplicationContext(), notificationCount); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:asia.covisoft.goom.gcm.GoOmUserGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from w w w . j a va 2 s . co m*/ */ private void sendNotification(String message, Driverconfirm response) { Intent intent = new Intent(this, HistoryDetailsActivity.class); trandingId = response.getTradingid(); intent.putExtra(Extras.TRADING_ID, trandingId); intent.putExtra(Extras.HISTORY_STATE, false); if (response.getValue().equals("tip")) { intent.putExtra(Extras.REQUEST_TIP, true); intent.putExtra(Extras.MAX_TIP, response.getMaxsuggest()); intent.putExtra(Extras.MIN_TIP, response.getMinsuggest()); cancelTip(); } intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle(getString(R.string.app_name_full)) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.botree.botree911_client.notification.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *///from w ww . j ava 2s. c o m private void sendNotification(String title, String messageBody) { int count = PreferenceUtility.getNoticationCount(MyFirebaseMessagingService.this); PreferenceUtility.saveNotificationCount(MyFirebaseMessagingService.this, (count + 1)); Intent intent = new Intent(this, SplashActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.setBigContentTitle(title); bigTextStyle.bigText(messageBody); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { notificationBuilder.setSmallIcon(R.drawable.ic_stat_name); notificationBuilder.setColor(ResourcesCompat.getColor(getResources(), R.color.colorGreenLight, null)); } else { notificationBuilder.setSmallIcon(R.mipmap.ic_launcher); } notificationBuilder.setContentTitle(title); notificationBuilder.setContentText(messageBody); notificationBuilder.setStyle(bigTextStyle); notificationBuilder.setAutoCancel(true); notificationBuilder.setSound(defaultSoundUri); notificationBuilder.setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(count /* ID of notification */, notificationBuilder.build()); }