Tuesday, April 9, 2013

android notification

protected void updateNotification(Integer _percent, Context mContext) {

CharSequence contentText = _percent + "% complete";
// publish it to the status bar
mNotification.setLatestEventInfo(mContext, "update Download",
contentText, mContentIntent);
mNotification.icon = android.R.drawable.stat_sys_download;
mNotificationManager.notify(NOTIFICATION_ID, mNotification);


public void createNotification(Context mContext) {
// get the notification manager
mNotificationManager = (NotificationManager) mContext

// create the notification
int icon = android.R.drawable.stat_sys_download;
CharSequence tickerText = "Download"; // Initial text that appears in
// the status bar
long when = System.currentTimeMillis();
mNotification = new Notification(icon, tickerText, when);

// create the content which is shown in the notification pulldown
String mContentTitle = "progress"; // Full title of the notification in
// the pull down
CharSequence contentText = "0% complete"; // Text of the notification in
// the pull down

// you have to set a PendingIntent on a notification to tell the system
// what you want it to do when the notification is selected
// I don't want to use this here so I'm just creating a blank one
Intent notificationIntent = new Intent();
mContentIntent = PendingIntent.getActivity(mContext, 0,
notificationIntent, 0);

// add the additional content and intent to the notification
mNotification.setLatestEventInfo(mContext, mContentTitle, contentText,

// make this notification appear in the 'Ongoing events' section
mNotification.flags = Notification.FLAG_ONGOING_EVENT;

// show the notification
mNotificationManager.notify(NOTIFICATION_ID, mNotification);

No comments:

Post a Comment