private Context mContext;
private int NOTIFICATION_ID = 0;
private Notification mNotification;
private NotificationManager mNotificationManager;
private PendingIntent mContentIntent;
private CharSequence mContentTitle;
private int icon=0;
public MyNotificationManager(Context context, int iconState)
{
mContext = context;
icon=iconState;
}
public void createNotification(int id, String title) {
NOTIFICATION_ID=id;
//create notification manager
mNotificationManager = (NotificationManager)
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
//create the notification
// icon=iconState
CharSequence tickerText = mContext.getString(R.string.download_ticker);
long when = System.currentTimeMillis();
mNotification = new Notification(icon, tickerText, when);
//create the content which is shown in the notification pulldown
mContentTitle = mContext.getString(R.string.content_title); //Full title of the notification in the pull down
CharSequence contentText = “0% complete”; //Text of the notification in the pull down
//It used for click event of notifion to open activity.
Intent notificationIntent = new Intent();
mContentIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0);
//add the additional content and intent to the notification
mNotification.setLatestEventInfo(mContext, title, contentText, mContentIntent);
//make this notification appear in the ‘Ongoing events’ section
mNotification.flags = Notification.FLAG_ONGOING_EVENT;
//show the notification
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
}
public void progressUpdate(int percentageComplete) {
//build up the new status message
CharSequence contentText = percentageComplete + “% complete”;
//publish it to the status bar
mNotification.setLatestEventInfo(mContext, mContentTitle, contentText, mContentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
}
/**
* called when the background task is complete, this removes the notification from the status bar.
* We could also use this to add a new ‘task complete’ notification
*/
public void completed(String msg)
{
mNotificationManager.cancel(NOTIFICATION_ID);
}
}