Context context = TutListDownloaderService.this .getApplicationContext(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(NOTIFICATION_SERVICE);
create notification:
Notification updateComplete = new Notification(); updateComplete.icon = android.R.drawable.stat_notify_sync; updateComplete.tickerText = context.getText(R.string.notification_title); updateComplete.when = System.currentTimeMillis();
Create a pending object:
Intent notificationIntent = new Intent(context,TutListActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); String contentTitle = context.getText(R.string.notification_title).toString(); String contentText; if (!result) { Log.w(DEBUG_TAG, "XML download and parse had errors"); contentText = context.getText(R.string.notification_info_fail).toString(); } else { contentText = context.getText( R.string.notification_info_success).toString(); } updateComplete.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
Finally, notify the user:
notificationManager.notify(LIST_UPDATE_NOTIFICATION, updateComplete);
source share