notify with PendingIntent - Android Android OS

Android examples for Android OS:Notification

Description

notify with PendingIntent

Demo Code


import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.support.v7.app.NotificationCompat;

public class Main{
    public static void notify(Context context, String title,
            String content, int icon, PendingIntent pendingIntent) {

        Notification notification = new NotificationCompat.Builder(context)
                .setContentTitle(title)/*w ww. j  a v  a  2  s  . c om*/
                .setContentText(content)
                .setSmallIcon(icon)
                .setContentIntent(pendingIntent)
                .setDefaults(
                        Notification.DEFAULT_SOUND
                                | Notification.DEFAULT_VIBRATE).build();

        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification);
    }
}

Related Tutorials