List of usage examples for android.app NotificationManager cancel
public void cancel(int id)
From source file:com.Duo.music.player.Services.AudioPlaybackService.java
/** * (non-Javadoc)/*from www.jav a 2s. com*/ * @see android.app.Service#onDestroy() */ @Override public void onDestroy() { //Notify the UI that the service is about to stop. mApp.broadcastUpdateUICommand(new String[] { Common.SERVICE_STOPPING }, new String[] { "" }); //Fire a broadcast message to the widget(s) to update them. updateWidgets(); //Send service stop event to GAnalytics. try { if (mApp.isGoogleAnalyticsEnabled()) { mTracker.set(Fields.SESSION_CONTROL, "end"); mTracker.send( MapBuilder.createTiming("Jams Service", System.currentTimeMillis() - mServiceStartTime, "Service duration.", "User stopped music playback.").build()); } } catch (Exception e) { e.printStackTrace(); } //Save the last track's info within the current queue. try { mApp.getSharedPreferences().edit().putLong("LAST_SONG_TRACK_POSITION", getCurrentMediaPlayer().getCurrentPosition()); } catch (Exception e) { e.printStackTrace(); mApp.getSharedPreferences().edit().putLong("LAST_SONG_TRACK_POSITION", 0); } //If the current song is repeating a specific range, reset the repeat option. if (getRepeatMode() == Common.REPEAT_SONG) { setRepeatMode(Common.REPEAT_OFF); } mFadeInVolume = 0.0f; mFadeOutVolume = 1.0f; //Unregister the headset plug receiver and RemoteControlClient. try { RemoteControlHelper.unregisterRemoteControlClient(mAudioManager, mRemoteControlClientCompat); unregisterReceiver(mHeadsetPlugReceiver); } catch (Exception e) { //Just null out the receiver if it hasn't been registered yet. mHeadsetPlugReceiver = null; } //Remove the notification. NotificationManager notificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(mNotificationId); try { mEqualizerHelper.releaseEQObjects(); mEqualizerHelper = null; } catch (Exception e1) { e1.printStackTrace(); mEqualizerHelper = null; } if (mMediaPlayer != null) mMediaPlayer.release(); if (mMediaPlayer2 != null) getMediaPlayer2().release(); mMediaPlayer = null; mMediaPlayer2 = null; //Close the cursor(s). try { getCursor().close(); setCursor(null); } catch (Exception e) { e.printStackTrace(); } //Final scrobbling. scrobbleTrack(SimpleLastFMHelper.PAUSE); /* * If A-B repeat is enabled, disable it to prevent the * next service instance from repeating the same section * over and over on the new track. */ if (getRepeatMode() == Common.A_B_REPEAT) setRepeatMode(Common.REPEAT_OFF); //Remove audio focus and unregister the audio buttons receiver. mAudioManagerHelper.setHasAudioFocus(false); mAudioManager.abandonAudioFocus(audioFocusChangeListener); mAudioManager.unregisterMediaButtonEventReceiver( new ComponentName(getPackageName(), HeadsetButtonsReceiver.class.getName())); mAudioManager = null; mMediaButtonReceiverComponent = null; mRemoteControlClientCompat = null; //Nullify the service object. mApp.setService(null); mApp.setIsServiceRunning(false); mApp = null; }
From source file:org.cvasilak.jboss.mobile.app.service.UploadToJBossServerService.java
@Override protected void onHandleIntent(Intent intent) { // initialize // extract details Server server = intent.getParcelableExtra("server"); String directory = intent.getStringExtra("directory"); String filename = intent.getStringExtra("filename"); // get the json parser from the application JsonParser jsonParser = new JsonParser(); // start the ball rolling... final NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setTicker(String.format(getString(R.string.notif_ticker), filename)) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_notif_large)) .setSmallIcon(R.drawable.ic_stat_notif_small) .setContentTitle(String.format(getString(R.string.notif_title), filename)) .setContentText(getString(R.string.notif_content_init)) // to avoid NPE on android 2.x where content intent is required // set an empty content intent .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0)).setOngoing(true); // notify user that upload is starting mgr.notify(NOTIFICATION_ID, builder.build()); // reset ticker for any subsequent notifications builder.setTicker(null);//from w w w . j a va 2 s . c o m AbstractHttpClient client = CustomHTTPClient.getHttpClient(); // enable digest authentication if (server.getUsername() != null && !server.getUsername().equals("")) { Credentials credentials = new UsernamePasswordCredentials(server.getUsername(), server.getPassword()); client.getCredentialsProvider().setCredentials( new AuthScope(server.getHostname(), server.getPort(), AuthScope.ANY_REALM), credentials); } final File file = new File(directory, filename); final long length = file.length(); try { CustomMultiPartEntity multipart = new CustomMultiPartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, new CustomMultiPartEntity.ProgressListener() { @Override public void transferred(long num) { // calculate percentage //System.out.println("transferred: " + num); int progress = (int) ((num * 100) / length); builder.setContentText(String.format(getString(R.string.notif_content), progress)); mgr.notify(NOTIFICATION_ID, builder.build()); } }); multipart.addPart(file.getName(), new FileBody(file)); HttpPost httpRequest = new HttpPost(server.getHostPort() + "/management/add-content"); httpRequest.setEntity(multipart); HttpResponse serverResponse = client.execute(httpRequest); BasicResponseHandler handler = new BasicResponseHandler(); JsonObject reply = jsonParser.parse(handler.handleResponse(serverResponse)).getAsJsonObject(); if (!reply.has("outcome")) { throw new RuntimeException(getString(R.string.invalid_response)); } else { // remove the 'upload in-progress' notification mgr.cancel(NOTIFICATION_ID); String outcome = reply.get("outcome").getAsString(); if (outcome.equals("success")) { String BYTES_VALUE = reply.get("result").getAsJsonObject().get("BYTES_VALUE").getAsString(); Intent resultIntent = new Intent(this, UploadCompletedActivity.class); // populate it resultIntent.putExtra("server", server); resultIntent.putExtra("BYTES_VALUE", BYTES_VALUE); resultIntent.putExtra("filename", filename); resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // the notification id for the 'completed upload' notification // each completed upload will have a different id int notifCompletedID = (int) System.currentTimeMillis(); builder.setContentTitle(getString(R.string.notif_title_uploaded)) .setContentText(String.format(getString(R.string.notif_content_uploaded), filename)) .setContentIntent( // we set the (2nd param request code to completedID) // see http://tinyurl.com/kkcedju PendingIntent.getActivity(this, notifCompletedID, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT)) .setAutoCancel(true).setOngoing(false); mgr.notify(notifCompletedID, builder.build()); } else { JsonElement elem = reply.get("failure-description"); if (elem.isJsonPrimitive()) { throw new RuntimeException(elem.getAsString()); } else if (elem.isJsonObject()) throw new RuntimeException( elem.getAsJsonObject().get("domain-failure-description").getAsString()); } } } catch (Exception e) { builder.setContentText(e.getMessage()).setAutoCancel(true).setOngoing(false); mgr.notify(NOTIFICATION_ID, builder.build()); } }
From source file:com.daiv.android.twitter.services.WidgetRefreshService.java
@Override public void onHandleIntent(Intent intent) { // it is refreshing elsewhere, so don't start if (WidgetRefreshService.isRunning || TimelineRefreshService.isRunning || CatchupPull.isRunning || !MainActivity.canSwitch) { return;/*from w w w .jav a 2 s. c o m*/ } WidgetRefreshService.isRunning = true; sharedPrefs = getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.refreshing) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.refreshing_widget) + "...") .setProgress(100, 100, true) .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.drawer_sync_dark)); NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); Context context = getApplicationContext(); AppSettings settings = AppSettings.getInstance(context); // if they have mobile data on and don't want to sync over mobile data if (Utils.getConnectionStatus(context) && !settings.syncMobile) { return; } Twitter twitter = Utils.getTwitter(context, settings); HomeDataSource dataSource = HomeDataSource.getInstance(context); int currentAccount = sharedPrefs.getInt("current_account", 1); List<twitter4j.Status> statuses = new ArrayList<twitter4j.Status>(); boolean foundStatus = false; Paging paging = new Paging(1, 200); long[] lastId; long id; try { lastId = dataSource.getLastIds(currentAccount); id = lastId[0]; } catch (Exception e) { WidgetRefreshService.isRunning = false; return; } paging.setSinceId(id); for (int i = 0; i < settings.maxTweetsRefresh; i++) { try { if (!foundStatus) { paging.setPage(i + 1); List<Status> list = twitter.getHomeTimeline(paging); statuses.addAll(list); if (statuses.size() <= 1 || statuses.get(statuses.size() - 1).getId() == lastId[0]) { Log.v("Test_inserting", "found status"); foundStatus = true; } else { Log.v("Test_inserting", "haven't found status"); foundStatus = false; } } } catch (Exception e) { // the page doesn't exist foundStatus = true; } catch (OutOfMemoryError o) { // don't know why... } } Log.v("Test_pull", "got statuses, new = " + statuses.size()); // hash set to remove duplicates I guess HashSet hs = new HashSet(); hs.addAll(statuses); statuses.clear(); statuses.addAll(hs); Log.v("Test_inserting", "tweets after hashset: " + statuses.size()); lastId = dataSource.getLastIds(currentAccount); int inserted = HomeDataSource.getInstance(context).insertTweets(statuses, currentAccount, lastId); if (inserted > 0 && statuses.size() > 0) { sharedPrefs.edit().putLong("account_" + currentAccount + "_lastid", statuses.get(0).getId()).commit(); } if (settings.preCacheImages) { startService(new Intent(this, PreCacheService.class)); } context.sendBroadcast(new Intent("com.daiv.android.Test.UPDATE_WIDGET")); getContentResolver().notifyChange(HomeContentProvider.CONTENT_URI, null); sharedPrefs.edit().putBoolean("refresh_me", true).commit(); mNotificationManager.cancel(6); WidgetRefreshService.isRunning = false; }
From source file:com.klinker.android.twitter.services.WidgetRefreshService.java
@Override public void onHandleIntent(Intent intent) { // it is refreshing elsewhere, so don't start if (WidgetRefreshService.isRunning || TimelineRefreshService.isRunning || CatchupPull.isRunning || !MainActivity.canSwitch) { return;/*from www .j a v a2s . c om*/ } WidgetRefreshService.isRunning = true; sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_icon) .setTicker(getResources().getString(R.string.refreshing) + "...") .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(getResources().getString(R.string.refreshing_widget) + "...") .setProgress(100, 100, true) .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.drawer_sync_dark)); NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); Context context = getApplicationContext(); AppSettings settings = AppSettings.getInstance(context); // if they have mobile data on and don't want to sync over mobile data if (Utils.getConnectionStatus(context) && !settings.syncMobile) { return; } Twitter twitter = Utils.getTwitter(context, settings); HomeDataSource dataSource = HomeDataSource.getInstance(context); int currentAccount = sharedPrefs.getInt("current_account", 1); List<twitter4j.Status> statuses = new ArrayList<twitter4j.Status>(); boolean foundStatus = false; Paging paging = new Paging(1, 200); long[] lastId; long id; try { lastId = dataSource.getLastIds(currentAccount); id = lastId[0]; } catch (Exception e) { WidgetRefreshService.isRunning = false; return; } paging.setSinceId(id); for (int i = 0; i < settings.maxTweetsRefresh; i++) { try { if (!foundStatus) { paging.setPage(i + 1); List<Status> list = twitter.getHomeTimeline(paging); statuses.addAll(list); if (statuses.size() <= 1 || statuses.get(statuses.size() - 1).getId() == lastId[0]) { Log.v("talon_inserting", "found status"); foundStatus = true; } else { Log.v("talon_inserting", "haven't found status"); foundStatus = false; } } } catch (Exception e) { // the page doesn't exist foundStatus = true; } catch (OutOfMemoryError o) { // don't know why... } } Log.v("talon_pull", "got statuses, new = " + statuses.size()); // hash set to remove duplicates I guess HashSet hs = new HashSet(); hs.addAll(statuses); statuses.clear(); statuses.addAll(hs); Log.v("talon_inserting", "tweets after hashset: " + statuses.size()); lastId = dataSource.getLastIds(currentAccount); int inserted = HomeDataSource.getInstance(context).insertTweets(statuses, currentAccount, lastId); if (inserted > 0 && statuses.size() > 0) { sharedPrefs.edit().putLong("account_" + currentAccount + "_lastid", statuses.get(0).getId()).commit(); } if (settings.preCacheImages) { startService(new Intent(this, PreCacheService.class)); } context.sendBroadcast(new Intent("com.klinker.android.talon.UPDATE_WIDGET")); getContentResolver().notifyChange(HomeContentProvider.CONTENT_URI, null); sharedPrefs.edit().putBoolean("refresh_me", true).commit(); mNotificationManager.cancel(6); WidgetRefreshService.isRunning = false; }
From source file:com.zuzhili.bussiness.helper.CCPHelper.java
/** * ???// w w w .j a v a2 s. c o m * content ? */ private void showMsgNotification(Context context, String content, String ticker, String listId) { // NotificationManager NotificationManager notificationManager = (NotificationManager) context .getSystemService(android.content.Context.NOTIFICATION_SERVICE); // ? Intent notificationIntent = new Intent(context, HomeTabActivity.class); // ??Activity notificationIntent.putExtra(Constants.TO_GROUPSLISTFRG, "ok"); notificationIntent.putExtra(Constants.CHANGE_SOCIAL, listId); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//Intent.FLAG_ACTIVITY_SINGLE_TOP| notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); notificationIntent.setData(Uri.parse("custom://" + System.currentTimeMillis())); PendingIntent contentItent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Notification?? Notification notification = new NotificationCompat.Builder(context) .setContentTitle(context.getString(R.string.new_msg_notification_title)).setContentText(content) .setSmallIcon(R.drawable.notify).setTicker(ticker).setContentIntent(contentItent) .setWhen(System.currentTimeMillis()).build(); //FLAG_AUTO_CANCEL ?? notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.flags |= Notification.FLAG_SHOW_LIGHTS; //DEFAULT_VIBRATE <uses-permission android:name="android.permission.VIBRATE" />?? notification.defaults = Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_SOUND; notification.ledARGB = Color.BLUE; notification.ledOnMS = 5000; // // ? NotificationNotificationManager notificationManager.cancel(0); notificationManager.notify(0, notification); }
From source file:com.akop.bach.service.XboxLiveServiceClient.java
private void notifyMessages(XboxLiveAccount account, long[] unreadMessages, List<Long> lastUnreadList) { NotificationManager mgr = getNotificationManager(); Context context = getContext(); int notificationId = 0x1000000 | ((int) account.getId() & 0xffffff); if (App.getConfig().logToConsole()) { String s = ""; for (Object unr : lastUnreadList) s += unr.toString() + ","; App.logv("Currently unread (%d): %s", lastUnreadList.size(), s); s = "";//w w w . j a v a 2 s . c o m for (Object unr : unreadMessages) s += unr.toString() + ","; App.logv("New unread (%d): %s", unreadMessages.length, s); } if (unreadMessages.length > 0) { int unreadCount = 0; for (Object unread : unreadMessages) { if (!lastUnreadList.contains(unread)) unreadCount++; } if (App.getConfig().logToConsole()) App.logv("%d computed new", unreadCount); if (unreadCount > 0) { String tickerTitle; String tickerText; if (unreadMessages.length == 1) { tickerTitle = context.getString(R.string.new_message); tickerText = context.getString(R.string.notify_message_pending_f, account.getScreenName(), Messages.getSender(context, unreadMessages[0])); } else { tickerTitle = context.getString(R.string.new_messages); tickerText = context.getString(R.string.notify_messages_pending_f, account.getScreenName(), unreadMessages.length, account.getDescription()); } Notification notification = new Notification(R.drawable.xbox_stat_notify_message, tickerText, System.currentTimeMillis()); Intent intent = new Intent(context, MessageList.class); intent.putExtra("account", account); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0); notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS; if (unreadMessages.length > 1) notification.number = unreadMessages.length; notification.ledOnMS = DEFAULT_LIGHTS_ON_MS; notification.ledOffMS = DEFAULT_LIGHTS_OFF_MS; notification.ledARGB = DEFAULT_LIGHTS_COLOR; notification.sound = account.getRingtoneUri(); if (account.isVibrationEnabled()) notification.defaults |= Notification.DEFAULT_VIBRATE; notification.setLatestEventInfo(context, tickerTitle, tickerText, contentIntent); mgr.notify(notificationId, notification); } } else // No unread messages { mgr.cancel(notificationId); } }
From source file:com.akop.bach.service.XboxLiveServiceClient.java
private void notifyFriends(XboxLiveAccount account, long[] friendsOnline, List<Long> lastFriendsOnline) { NotificationManager mgr = getNotificationManager(); Context context = getContext(); int notificationId = 0x2000000 | ((int) account.getId() & 0xffffff); if (App.getConfig().logToConsole()) { String s = ""; for (Object unr : lastFriendsOnline) s += unr.toString() + ","; App.logv("Currently online (%d): %s", lastFriendsOnline.size(), s); s = "";//www . j a v a 2s . co m for (Object unr : friendsOnline) s += unr.toString() + ","; App.logv("New online (%d): %s", friendsOnline.length, s); } if (friendsOnline.length > 0) { int newOnlineCount = 0; for (Object online : friendsOnline) if (!lastFriendsOnline.contains(online)) newOnlineCount++; if (App.getConfig().logToConsole()) App.logv("%d computed new; %d online now; %d online before", newOnlineCount, friendsOnline.length, lastFriendsOnline.size()); if (newOnlineCount > 0) { // Prepare notification objects String tickerTitle; String tickerText; if (friendsOnline.length == 1) { tickerTitle = context.getString(R.string.friend_online); tickerText = context.getString(R.string.notify_friend_online_f, Friends.getGamertag(context, friendsOnline[0]), account.getDescription()); } else { tickerTitle = context.getString(R.string.friends_online); tickerText = context.getString(R.string.notify_friends_online_f, account.getScreenName(), friendsOnline.length, account.getDescription()); } Notification notification = new Notification(R.drawable.xbox_stat_notify_friend, tickerText, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; Intent intent = new Intent(context, FriendList.class); intent.putExtra("account", account); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0); notification.setLatestEventInfo(context, tickerTitle, tickerText, contentIntent); // New users online if (friendsOnline.length > 1) notification.number = friendsOnline.length; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledOnMS = DEFAULT_LIGHTS_ON_MS; notification.ledOffMS = DEFAULT_LIGHTS_OFF_MS; notification.ledARGB = DEFAULT_LIGHTS_COLOR; notification.sound = account.getRingtoneUri(); if (account.isVibrationEnabled()) notification.defaults |= Notification.DEFAULT_VIBRATE; mgr.notify(notificationId, notification); } } else // No unread messages { mgr.cancel(notificationId); } }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
private void CancelNotification() { NotificationManager notificationManager = (NotificationManager) contextWrapper .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(1959); }
From source file:com.viettel.dms.util.StatusNotificationHandler.java
/** * //from w w w. jav a2s . c om * tao notification len status notification * @author: AnhND * @param appContext * @param activity * @return: void * @throws: */ private void postNotificationMessage(GlobalBaseActivity activity) { NotificationManager notificationManager = (NotificationManager) GlobalInfo.getInstance().getAppContext() .getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.icon_app_small; BitmapDrawable bd = (BitmapDrawable) GlobalInfo.getInstance().getAppContext().getResources() .getDrawable(icon); int iconWidth = bd.getBitmap().getWidth(); CharSequence tickerText = getMessageNotify(); long when = System.currentTimeMillis(); // noi dung trong status bar khi keo xuong xem thong bao CharSequence contentText = Constants.STR_BLANK; contentText = getMessageNotify(); int screenWidth = ((WindowManager) GlobalInfo.getInstance().getAppContext() .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth(); screenWidth -= iconWidth;//for icon TextView textView = new TextView(GlobalInfo.getInstance().getAppContext()); int count = tickerText.length(); StringBuilder wrapTickerText = new StringBuilder(); wrapTickerText.append(tickerText); while (count > 0) { if (count < tickerText.length()) { wrapTickerText.append("..."); } float measuredWidth = textView.getPaint().measureText(wrapTickerText.toString()); if (measuredWidth < screenWidth) { break; } count--; wrapTickerText.setLength(count); } Intent notificationIntent = initIntentMessage(); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); //TamQP: fix bug _ phai truyen requestCode de phan biet PendingIntent lien tiep giong nhau int requestCode = (int) System.currentTimeMillis(); PendingIntent contentIntent = PendingIntent.getActivity(GlobalInfo.getInstance().getAppContext(), requestCode, notificationIntent, 0); // Notification notification = new Notification(icon, wrapTickerText, when); // Intent notificationIntent = initIntentMessage(); // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // //TamQP: fix bug _ phai truyen requestCode de phan biet PendingIntent lien tiep giong nhau // int requestCode = (int) System.currentTimeMillis(); // PendingIntent contentIntent = PendingIntent.getActivity(GlobalInfo.getInstance().getAppContext(), requestCode, notificationIntent, 0); // // notification.setLatestEventInfo(GlobalInfo.getInstance().getAppContext(), StringUtil.getString(R.string.app_name), contentText, contentIntent); // notification.flags |= Notification.FLAG_AUTO_CANCEL; // notification.defaults = Notification.DEFAULT_ALL; // // notificationManager.cancel(NOTIFICATION_MESSAGE_ID); // notificationManager.notify(NOTIFICATION_MESSAGE_ID, notification); NotificationCompat.Builder builder = new NotificationCompat.Builder( GlobalInfo.getInstance().getAppContext()); Notification notification = builder.setContentIntent(contentIntent).setSmallIcon(icon) .setTicker(contentText).setWhen(when).setAutoCancel(true) .setContentTitle(StringUtil.getString(R.string.app_name)).setContentText(contentText).build(); notificationManager.cancel(NOTIFICATION_MESSAGE_ID); notificationManager.notify(NOTIFICATION_MESSAGE_ID, notification); }