Last active
December 14, 2015 13:49
-
-
Save marcelohd/5096259 to your computer and use it in GitHub Desktop.
NotificationCompat.Builder ANDROID
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
| public void setupNotification(){ | |
| NotificationCompat.Builder mBuilder = | |
| new NotificationCompat.Builder(this) | |
| .setSmallIcon(R.drawable.ic_launcher) | |
| .setContentTitle("Title") | |
| .setContentText("TEXT"); | |
| mBuilder.setOngoing(true); | |
| // Creates an explicit intent for an Activity in your app | |
| Intent resultIntent = new Intent(this, MainActivity_v11.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_v11.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); | |
| mNotificationManager = | |
| (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); | |
| // mId allows you to update the notification later on. | |
| mNotificationManager.notify(222, mBuilder.build()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment