First we need to use Notification builder
Then we need to have a intent
Now, we create a pending activity
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("My notification") .setContentText("Hello World!");
Then we need to have a intent
Intent resultIntent = new Intent(this, ResultActivity.class);need not to say that if it is being defined in a inner class then instead of writing this we write MainActivitiy.this
Now, we create a pending activity
PendingIntent resultPendingIntent = PendingIntent.getActivity( this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);WE make our builder content intent equal to our pending activity
mBuilder.setContentIntent(resultPendingIntent);
Now the last thing i.e. to issue the notification , which is done with the help of notification manager, which get the android notification service
int mNotificationId = 001; // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(mNotificationId, mBuilder.build());
No comments:
Post a Comment