Introduction
Here, i am describes about :
- How to send Notification from your application.
- How to Customize the Notification.
- How to add Action Button in Notification.
- How to implemented Explicit Intent in Notification.
-
How to implemented Implicit Intent in Notification.
`// Set Notification Title String strTitle = "You Got New Notification."; // Set Notification Text String strText = "Hi,How are You?"; //This is the proper solution for Open Some Activity after clicking the action in notification // Open InfoActivity Class on "Info" Button Click Intent intentInfo = new Intent(this, InfoActivity.class); // Send data to InfoActivity Class intentInfo.putExtra("title", strTitle); intentInfo.putExtra("text", strText); // Open InfoActivity.java Activity PendingIntent pIntentInfo = PendingIntent.getActivity(this, 0, intentInfo, PendingIntent.FLAG_UPDATE_CURRENT); //This is the proper solution for dismiss the dialog //Create an Intent for the BroadcastReceiver Intent intentDismiss = new Intent(context, HandleBroadcastReceiver.class); //Create the PendingIntent PendingIntent pIntentDismiss = PendingIntent.getBroadcast(context, 0, intentDismiss, 0); //Create Notification using NotificationCompat.Builder NotificationCompat.Builder builder = new NotificationCompat.Builder(this) // Set Icon .setSmallIcon(R.drawable.ic_launcher) // Set Title .setContentTitle(strTitle) // Set Text .setContentText(strText) // Add an Action Button below Notification .addAction(android.R.drawable.ic_menu_close_clear_cancel, "Dismiss", pIntentDismiss) .addAction(android.R.drawable.ic_menu_info_details, "Info", pIntentInfo) // Set PendingIntent into Notification .setContentIntent(pIntentDismiss) // showing action button on notification .setPriority(Notification.PRIORITY_MAX) .setWhen(0) .setColor(0x0079c0) /* Increase notification number every time a new notification arrives */ .setNumber(++numMessages) // Dismiss Notification .setAutoCancel(true); // Create Notification Manager NotificationManager notificationmanager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Build Notification with Notification Manager notificationmanager.notify(0, builder.build());`