Created
November 9, 2016 06:27
-
-
Save msomu/3a3d1f8e95c12862f898ec30246985f8 to your computer and use it in GitHub Desktop.
This will create a larger notification InBoxStyle Notification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void createInboxStyleNotification() { | |
| NotificationCompat.Builder mBuilder = | |
| new NotificationCompat.Builder(this) | |
| .setSmallIcon(R.mipmap.ic_launcher) | |
| .setContentTitle("My notification") | |
| .setContentText("Hello World!"); | |
| NotificationCompat.InboxStyle inboxStyle = | |
| new NotificationCompat.InboxStyle(); | |
| String[] events = new String[6]; | |
| events[0] = "Line 1"; | |
| events[1] = "Line 2"; | |
| events[2] = "Line 3"; | |
| events[3] = "Line 4"; | |
| events[4] = "Line 5"; | |
| events[5] = "Line 6"; | |
| // Sets a title for the Inbox in expanded layout | |
| inboxStyle.setBigContentTitle("Event tracker details:"); | |
| // Moves events into the expanded layout | |
| for (String event : events) { | |
| inboxStyle.addLine(event); | |
| } | |
| // Moves the expanded layout object into the notification object. | |
| mBuilder.setStyle(inboxStyle); | |
| Intent resultIntent = new Intent(this, MainActivity.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(this); | |
| // Adds the back stack for the Intent (but not the Intent itself) | |
| stackBuilder.addParentStack(MainActivity.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.setAutoCancel(true); | |
| mBuilder.setContentIntent(resultPendingIntent); | |
| NotificationManager mNotificationManager = | |
| (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); | |
| // mId allows you to update the notification later on. | |
| mNotificationManager.notify(101, mBuilder.build()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment