Notification

Showing posts with label Notification. Show all posts
Showing posts with label Notification. Show all posts

Thursday, December 4, 2014

Creating notification in android.....


This article shows how to create notification in android.


public MyNotification(Context ctx){
super();
this.ctx=ctx;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) ctx.getSystemService(ns);
long when = System.currentTimeMillis();
Notification.Builder builder = new Notification.Builder(ctx);
notification=builder.getNotification();
notification.when=when;
notification.icon=R.drawable.mp3_icon;
remoteViews=new RemoteViews(ctx.getPackageName(),                        R.layout.service_layout);
notification.contentView = remoteViews;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(5, notification);
}