Tutorial by Examples

This example shows how to create a simple notification that starts an application when the user clicks it. Specify the notification's content: NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) // notification icon .se...
Here is how to make a Heads Up Notification for capable devices, and use a Ticker for older devices. // Tapping the Notification will open up MainActivity Intent i = new Intent(this, MainActivity.class); // an action to use later // defined as an app constant: // public static final String ME...
NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.some_small_icon) .setContentTitle("Title") .setContentText("This is a test notification with MAX priority")...
Sometimes it is required to display a notification at a specific time, a task that unfortunately is not trivial on the Android system, as there is no method setTime() or similiar for notifications. This example outlines the steps needed to schedule notifications using the AlarmManager: Add a Broa...
If you want have a long text to display in the context, you need to set a custom content. For example, you have this: But you wish your text will be fully shown: All you need to do, is to add a style to your content like below: private void generateNotification(Context context) { ...
PendingIntent pendingIntent = PendingIntent.getActivity(context, uniqueIntentId, intent, PendingIntent.FLAG_CANCEL_CURRENT); final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.remote_view_notification); remoteViews.setImageViewResource(R.id.remote...
If you're creating an image, decoding an image, or resizing an image to fit the large notification image area, you can get the correct pixel dimensions like so: Resources resources = context.getResources(); int width = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_width)...
// Cancel older notification with same id, NotificationManager notificationMgr = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); notificationMgr.cancel(CALL_NOTIFY_ID);// any constant value // Create Pending Intent, Intent notificationIntent = null; PendingInt...

Page 1 of 1