Advertisement
dzikovskyy

Show Notification, Android

Jun 16th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. private void showNotification() {
  2.  
  3.         NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
  4.                 .setContentTitle(getText(R.string.app_name))
  5.                 .setContentText(getText(R.string.notification_text))
  6.                 .setSmallIcon(R.drawable.right_footprint)
  7.                 .setColor(getResources().getColor(R.color.blue_step_counter_color));
  8.  
  9.         // Creates an explicit intent for an Activity in your app
  10.         Intent resultIntent = new Intent(this, MainActivity.class);
  11.         // The stack builder object will contain an artificial back stack for the
  12.         // started Activity.
  13.         // This ensures that navigating backward from the Activity leads out of
  14.         // your application to the Home screen.
  15.         TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
  16.         // Adds the back stack for the Intent (but not the Intent itself)
  17.         stackBuilder.addParentStack(MainActivity.class);
  18.         // Adds the Intent that starts the Activity to the top of the stack
  19.         stackBuilder.addNextIntent(resultIntent);
  20.         PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
  21.         mBuilder.setContentIntent(resultPendingIntent);
  22.         Notification notification = mBuilder.build();
  23.         notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
  24.         // notificationId allows you to update the notification later on.
  25.         mNotificationManager.notify(notificationId, notification);
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement