List of usage examples for android.app NotificationManager cancel
public void cancel(int id)
From source file:com.dotcom.jamaatAdmin.fcm.GCMListenerService.java
/** * Create and show a simple notification containing the received GCM * message./*from www .j a v a 2 s . c o m*/ * <p/> * <p/> * GCM message received. */ public void displayNotificationInNotificationBar(Map data) { try { String messageData = data.get("message").toString(); int notifyID = Constants.NOTIFICATION_ID; //String eData = data.getString("extra_data"); String message = ""; if (!TextUtils.isEmpty(messageData)) { JSONObject extra_data = new JSONObject(messageData); message = extra_data.optString("message"); } // This intent is fired when notification is clicked NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Intent intent; String messages = SharedPreferencesManager.getStringPreference("notificationMessage", null); if (messages != null && !messages.isEmpty()) { messages = message + "," + messages; SharedPreferencesManager.setPreference("notificationMessage", messages); intent = new Intent(this, NotificationActivity.class); } else { SharedPreferencesManager.setPreference("notificationMessage", message); intent = new Intent(this, NotificationActivity.class); } intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); String currentMessages = SharedPreferencesManager.getStringPreference("notificationMessage", null); String[] messagesArray = currentMessages.split(","); int count = messagesArray.length; if (messagesArray.length == 0) { notificationManager.cancel(notifyID); return; } final String GROUP_KEY_MESSAGES = "group_key_messages"; // Group notification that will be visible on the phone NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); mBuilder.setTicker(getString(R.string.app_name)).setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.app_name)).setSound(defaultSoundUri).setAutoCancel(true) .setOnlyAlertOnce(false) // .setPriority(Notification.PRIORITY_MAX) // .setOngoing(true) // .setWhen( System.currentTimeMillis() ) .setContentIntent(pendingIntent).setSmallIcon(R.mipmap.ic_launcher).setGroup(GROUP_KEY_MESSAGES) .setGroupSummary(true).build(); NotificationCompat.Style style; if (count > 1) { NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); style = inboxStyle; mBuilder.setContentTitle(getString(R.string.app_name)); for (String r : messagesArray) { inboxStyle.addLine(r); } mBuilder.setContentText(count + " new messages"); inboxStyle.setBigContentTitle(getString(R.string.app_name)); inboxStyle.setSummaryText(count + " new messages"); } else { NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); style = bigTextStyle; // bigTextStyle.setBigContentTitle(messagesArray[0].substring(0, 10).concat(" ...")); bigTextStyle.setBigContentTitle(getString(R.string.app_name)); mBuilder.setContentText(message); bigTextStyle.bigText(message); // bigTextStyle.setSummaryText(count + " new event"); } mBuilder.setStyle(style); NotificationManagerCompat notificationManager1 = NotificationManagerCompat.from(this); notificationManager1.notify(notifyID, mBuilder.build()); } catch (Exception ex) { } }
From source file:com.dotcom.jamaat.fcm.GCMListenerService.java
/** * Create and show a simple notification containing the received GCM * message.// w w w . j a v a 2 s . co m * <p/> * <p/> * GCM message received. */ public void displayNotificationInNotificationBar(Map data) { try { String messageData = data.get("message").toString(); int notifyID = Constants.NOTIFICATION_ID; //String eData = data.getString("extra_data"); String message = ""; if (!TextUtils.isEmpty(messageData)) { JSONObject extra_data = new JSONObject(messageData); message = extra_data.optString("message"); } // This intent is fired when notification is clicked NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Intent intent; String messages = SharedPreferencesManager.getStringPreference("notificationMessage", null); if (messages != null && !messages.isEmpty()) { messages = message + ";" + messages; SharedPreferencesManager.setPreference("notificationMessage", messages); intent = new Intent(this, NotificationActivity.class); } else { SharedPreferencesManager.setPreference("notificationMessage", message); intent = new Intent(this, NotificationActivity.class); } intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); String currentMessages = SharedPreferencesManager.getStringPreference("notificationMessage", null); String[] messagesArray = currentMessages.split(";"); int count = messagesArray.length; if (messagesArray.length == 0) { notificationManager.cancel(notifyID); return; } final String GROUP_KEY_MESSAGES = "group_key_messages"; // Group notification that will be visible on the phone NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); mBuilder.setTicker(getString(R.string.app_name)).setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.app_name)).setSound(defaultSoundUri).setAutoCancel(true) .setOnlyAlertOnce(false).setPriority(Notification.PRIORITY_MAX) // .setOngoing(true) // .setWhen( System.currentTimeMillis() ) .setContentIntent(pendingIntent).setSmallIcon(R.mipmap.ic_launcher).setGroup(GROUP_KEY_MESSAGES) .setGroupSummary(true).build(); NotificationCompat.Style style; if (count > 1) { NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); style = inboxStyle; mBuilder.setContentTitle(getString(R.string.app_name)); for (String r : messagesArray) { inboxStyle.addLine(r); } mBuilder.setContentText(count + " new messages"); inboxStyle.setBigContentTitle(getString(R.string.app_name)); inboxStyle.setSummaryText(count + " new messages"); } else { NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); style = bigTextStyle; // bigTextStyle.setBigContentTitle(messagesArray[0].substring(0, 10).concat(" ...")); bigTextStyle.setBigContentTitle(getString(R.string.app_name)); mBuilder.setContentText(message); bigTextStyle.bigText(message); // bigTextStyle.setSummaryText(count + " new event"); } mBuilder.setStyle(style); NotificationManagerCompat notificationManager1 = NotificationManagerCompat.from(this); notificationManager1.notify(notifyID, mBuilder.build()); } catch (Exception ex) { } }
From source file:org.tomahawk.tomahawk_android.services.PlaybackService.java
/** * Pause playback./*from ww w. jav a 2 s . c o m*/ * * @param dismissNotificationOnPause if true, dismiss notification on pause, otherwise don't */ public void pause(boolean dismissNotificationOnPause) { Log.d(TAG, "pause, dismissing Notification:" + dismissNotificationOnPause); mPlayState = PLAYBACKSERVICE_PLAYSTATE_PAUSED; EventBus.getDefault().post(new PlayStateChangedEvent()); handlePlayState(); if (dismissNotificationOnPause) { mShowingNotification = false; stopForeground(true); giveUpAudioFocus(); NotificationManager notificationManager = (NotificationManager) TomahawkApp.getContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(PLAYBACKSERVICE_NOTIFICATION_ID); } else { updateNotification(); } updateLockscreenPlayState(); }
From source file:com.daiv.android.twitter.ui.compose.Compose.java
public void makeFailedNotification(String text) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_icon) .setContentTitle(getResources().getString(R.string.tweet_failed)) .setContentText(getResources().getString(R.string.tap_to_retry)); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(5, mBuilder.build()); mNotificationManager.cancel(6); }
From source file:edu.cmu.cylab.starslinger.util.NotificationBroadcastReceiver.java
@SuppressWarnings("deprecation") public static void doUnseenMessagesNotification(Context ctx, int msgCount, boolean giveNotificationFeedback) throws OutOfMemoryError { long when = System.currentTimeMillis(); // notification time // To create a status bar notification: // Get a reference to the NotificationManager: String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) ctx.getSystemService(ns); String tickerText = ctx.getString(R.string.title_NotifyFileAvailable); String contentTitle = String.format(Locale.getDefault(), "%s (%d)", ctx.getString(R.string.app_name), msgCount);// w w w. ja v a 2 s . co m String contentText = String.format(ctx.getString(R.string.label_ClickForNMsgs), msgCount); Intent intent = makeMessagesNotificationIntent(ctx); intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // the next two lines initialize the Notification, using the // configurations above int visibleMsgCount = msgCount != 1 ? msgCount : 0; NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)// .setContentIntent(contentIntent)// .setSmallIcon(R.drawable.ic_stat_notify_msg)// .setTicker(tickerText)// .setWhen(when)// .setAutoCancel(true)// .setContentTitle(contentTitle)// .setContentText(contentText)// .setNumber(visibleMsgCount)// .setVisibility(NotificationCompat.VISIBILITY_SECRET); try { builder.setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_launcher)); } catch (OutOfMemoryError e) { // ignore icon when out of memory } // set notification alerts based on user preferences int defaults = 0; if (SafeSlingerPrefs.getNotificationVibrate() && giveNotificationFeedback) { defaults |= Notification.DEFAULT_VIBRATE; } String ringtoneStr = SafeSlingerPrefs.getNotificationRingTone(); builder.setSound( TextUtils.isEmpty(ringtoneStr) || !giveNotificationFeedback ? null : Uri.parse(ringtoneStr)); defaults |= Notification.DEFAULT_LIGHTS; builder.setDefaults(defaults); Notification n = builder.build(); // total messages seen... n.number = visibleMsgCount; // API <11 if (msgCount != 1) { // cancel old one since we want to avoid the "1" when updating // number nm.cancel(HomeActivity.NOTIFY_NEW_MSG_ID); } // Pass the Notification to the NotificationManager: nm.notify(HomeActivity.NOTIFY_NEW_MSG_ID, n); }
From source file:com.klinker.android.twitter.activities.compose.Compose.java
public void makeFailedNotification(String text) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_icon) .setContentTitle(getResources().getString(R.string.tweet_failed)) .setContentText(getResources().getString(R.string.tap_to_retry)); Intent resultIntent = new Intent(this, RetryCompose.class); QueuedDataSource.getInstance(this).createDraft(text, settings.currentAccount); resultIntent.setAction(Intent.ACTION_SEND); resultIntent.setType("text/plain"); resultIntent.putExtra("failed_notification", true); PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, 0); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(5, mBuilder.build()); mNotificationManager.cancel(6); }
From source file:com.klinker.android.twitter.activities.compose.Compose.java
public void finishedTweetingNotification() { new Handler().postDelayed(new Runnable() { @Override/* w ww. j ava 2s . c om*/ public void run() { try { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_icon) .setContentTitle(getResources().getString(R.string.tweet_success)).setOngoing(false) .setTicker(getResources().getString(R.string.tweet_success)); if (settings.vibrate) { Log.v("talon_vibrate", "vibrate on compose"); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 50, 500 }; v.vibrate(pattern, -1); } NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); // cancel it immediately, the ticker will just go off mNotificationManager.cancel(6); } catch (Exception e) { // not attached? } } }, 500); }
From source file:com.daiv.android.twitter.ui.compose.Compose.java
public void finishedTweetingNotification() { new Handler().postDelayed(new Runnable() { @Override// w w w . ja v a 2 s .com public void run() { try { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_icon) .setContentTitle(getResources().getString(R.string.tweet_success)).setOngoing(false) .setTicker(getResources().getString(R.string.tweet_success)); if (settings.vibrate) { Log.v(TAG + "Test_vibrate", "vibrate on compose"); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 50, 500 }; v.vibrate(pattern, -1); } NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); // cancel it immediately, the ticker will just go off mNotificationManager.cancel(6); sendMessage(); } catch (Exception e) { // not attached? } } }, 500); }
From source file:com.dafeng.upgradeapp.util.AutoUpdateApk.java
protected void raise_notification() { String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) context.getSystemService(ns); String update_file = preferences.getString(UPDATE_FILE, ""); if (update_file.length() > 0) { setChanged();/*from w ww . j a va 2s . c om*/ notifyObservers(AUTOUPDATE_HAVE_UPDATE); // raise notification Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis()); notification.flags |= NOTIFICATION_FLAGS; CharSequence contentTitle = appName + " update available"; CharSequence contentText = "Select to install"; Intent notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setDataAndType( Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file), ANDROID_PACKAGE); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); nm.notify(NOTIFICATION_ID, notification); } else { nm.cancel(NOTIFICATION_ID); } }
From source file:org.eclipse.paho.android.service.MqttConnection.java
private void parseMqttMessageV2(String topic, MqttMessage mqttMessage) throws Exception { Log.v("mqtt", "parseMqttMessageV2"); Context ctx = NanuService.getContext(); byte origMqttMsgByte[] = mqttMessage.getPayload(); int mqttIndex = 0; boolean processVTagSuccess = false; boolean processPTagSuccess = false; long mqttPacketValue = 0; boolean processTTagSuccess = false; long mqttTimestampValue = 0; boolean processLTagSuccess = false; int mqttMsgLengthValue = 0; boolean processMTagSuccess = false; String mqttMessageValue = ""; String mqttMembersValue = ""; boolean processGTagSuccess = false; long mqttGroupIDValue = 0; boolean processSTagSuccess = false; String mqttSubjectValue = ""; boolean processCTagSuccess = false; int mqttMemberCountValue = 0; boolean processNTagSuccess = false; int mqttAdminCountValue = 0; boolean processATagSuccess = false; String mqttAdminsValue = ""; String[] topicArray = topic.split("\\/"); String sender = topicArray[2]; if (topicArray.length == 4) { processGTagSuccess = true;/*from w w w. j ava2 s . c o m*/ try { mqttGroupIDValue = Long.parseLong(topicArray[3].toString().trim()); } catch (NumberFormatException nfe) { processGTagSuccess = false; nfe.printStackTrace(); } if (mqttGroupIDValue == 0) { try { mqttGroupIDValue = Long.valueOf(topicArray[3].trim()); } catch (Exception err) { processGTagSuccess = false; err.printStackTrace(); } } } String mqttMsgDateValue = ""; for (int indexMqttCounter = 0; indexMqttCounter < origMqttMsgByte.length; indexMqttCounter++) { /* Log.v(SettingsManager.TAG, "MqttService origMqttMsgByte[" + indexMqttCounter + "] = " + origMqttMsgByte[indexMqttCounter]); */ } for (int indexMqttCounter = 0; indexMqttCounter < origMqttMsgByte.length; indexMqttCounter++) { if (indexMqttCounter == 0) { mqttIndex = indexMqttCounter; long mqttVTag = getMqttTag(origMqttMsgByte, mqttIndex); if (mqttVTag != -1) { if (mqttVTag == 86) // "V" { processVTagSuccess = true; mqttIndex = mqttIndex + 2; } else { processVTagSuccess = false; break; } } } else { if (mqttIndex == indexMqttCounter) { long mqttTag = getMqttTag(origMqttMsgByte, mqttIndex); if (mqttTag != -1) { if (mqttTag == 80) /* "P" */ { mqttIndex = mqttIndex + 1; long mPValue = origMqttMsgByte[mqttIndex]; mqttPacketValue = mPValue; mqttIndex = mqttIndex + 1; processPTagSuccess = true; } else if (mqttTag == 84) /* "T" */ { mqttIndex = mqttIndex + 1; byte timeStampArray[] = new byte[8]; for (int i = 0; i < 8; i++) { timeStampArray[i] = origMqttMsgByte[mqttIndex + i]; } mqttTimestampValue = ByteBuffer.wrap(timeStampArray).order(ByteOrder.LITTLE_ENDIAN) .getLong(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); String messageYear = sdf.format(mqttTimestampValue); if (messageYear.length() != 4) { mqttTimestampValue = ByteBuffer.wrap(timeStampArray).order(ByteOrder.BIG_ENDIAN) .getLong(); } SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String messageDate = sdfDate.format(mqttTimestampValue); processTTagSuccess = true; mqttIndex = mqttIndex + 8; } else if (mqttTag == 76) /* "L" */ { if (processPTagSuccess) { if (mqttPacketValue == -128 || (mqttPacketValue == -117) || (mqttPacketValue == -115) || (mqttPacketValue == -126)) { mqttIndex = mqttIndex + 1; mqttMsgLengthValue = origMqttMsgByte[mqttIndex]; processLTagSuccess = true; mqttIndex = mqttIndex + 1; } else if (mqttPacketValue == 0) { mqttIndex = mqttIndex + 1; byte msgLengthArray[] = new byte[4]; for (int i = 0; i < 4; i++) { msgLengthArray[i] = origMqttMsgByte[mqttIndex + i]; } mqttMsgLengthValue = ByteBuffer.wrap(msgLengthArray) .order(ByteOrder.LITTLE_ENDIAN).getInt(); processLTagSuccess = true; mqttIndex = mqttIndex + 4; } } } else if (mqttTag == 77) /* "M" */ { if (processPTagSuccess) { if ((mqttPacketValue == -128) || (mqttPacketValue == -124) || (mqttPacketValue == -126) || (mqttPacketValue == -117)) { if (processCTagSuccess) { mqttIndex = mqttIndex + 1; for (int i = 0; i < mqttMemberCountValue; i++) { byte groupMembersArray[] = new byte[8]; for (int j = 0; j < 8; j++) { groupMembersArray[j] = origMqttMsgByte[mqttIndex + j]; } long participants = ByteBuffer.wrap(groupMembersArray) .order(ByteOrder.LITTLE_ENDIAN).getLong(); mqttIndex = mqttIndex + 8; if (i == (mqttMemberCountValue - 1)) { mqttMembersValue = mqttMembersValue + participants; } else { mqttMembersValue = mqttMembersValue + participants + ","; } } processMTagSuccess = true; } else { break; } } else if (mqttPacketValue == 0) { if (processLTagSuccess) { mqttIndex = mqttIndex + 1; if (mqttMsgLengthValue > 0) { byte messageArray[] = null; try { messageArray = new byte[mqttMsgLengthValue]; } catch (Exception err) { err.printStackTrace(); processMTagSuccess = false; break; } for (int i = 0; i < mqttMsgLengthValue; i++) { messageArray[i] = origMqttMsgByte[mqttIndex + i]; } mqttMessageValue = new String(messageArray); processMTagSuccess = true; mqttIndex = mqttIndex + mqttMsgLengthValue + 1; } } else { break; } } } } else if (mqttTag == 71) /* "G" */ { mqttIndex = mqttIndex + 1; byte groupIDArray[] = new byte[8]; for (int i = 0; i < 8; i++) { groupIDArray[i] = origMqttMsgByte[mqttIndex + i]; } mqttGroupIDValue = ByteBuffer.wrap(groupIDArray).order(ByteOrder.LITTLE_ENDIAN) .getLong(); processGTagSuccess = true; mqttIndex = mqttIndex + 8; } else if (mqttTag == 83) /* "S" */ { if (processLTagSuccess) { mqttIndex = mqttIndex + 1; if (mqttMsgLengthValue > 0) { byte subjectArray[] = null; try { subjectArray = new byte[mqttMsgLengthValue]; } catch (Exception err) { err.printStackTrace(); processSTagSuccess = false; break; } for (int i = 0; i < mqttMsgLengthValue; i++) { subjectArray[i] = origMqttMsgByte[mqttIndex + i]; } mqttSubjectValue = new String(subjectArray); processSTagSuccess = true; mqttIndex = mqttIndex + mqttMsgLengthValue; } } else { break; } } else if (mqttTag == 67) /* "C" */ { mqttIndex = mqttIndex + 1; mqttMemberCountValue = origMqttMsgByte[mqttIndex]; processCTagSuccess = true; mqttIndex = mqttIndex + 1; } else if (mqttTag == 78) /* "N" */ { mqttIndex = mqttIndex + 1; mqttAdminCountValue = origMqttMsgByte[mqttIndex]; processNTagSuccess = true; mqttIndex = mqttIndex + 1; } else if (mqttTag == 65) /* "A" */ { if (processPTagSuccess) { if (mqttPacketValue == -117) { if (processNTagSuccess) { mqttIndex = mqttIndex + 1; for (int i = 0; i < mqttAdminCountValue; i++) { byte groupAdminsArray[] = new byte[8]; for (int j = 0; j < 8; j++) { groupAdminsArray[j] = origMqttMsgByte[mqttIndex + j]; } long admins = ByteBuffer.wrap(groupAdminsArray) .order(ByteOrder.LITTLE_ENDIAN).getLong(); mqttIndex = mqttIndex + 8; if (i == (mqttAdminCountValue - 1)) { mqttAdminsValue = mqttAdminsValue + admins; } else { mqttAdminsValue = mqttAdminsValue + admins + ","; } } processATagSuccess = true; } else { break; } } } } else { break; } } else { break; } } } } if (!processVTagSuccess) { return; } PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); if (isScreenOn == false) { WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyLock"); if (wl.isHeld()) { wl.release(); } wl.acquire(10000); WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyCpuLock"); if (wl_cpu.isHeld()) { wl_cpu.release(); } wl_cpu.acquire(10000); } String message = mqttMessageValue; Log.v("mqtt", "from: " + sender); Log.v("mqtt", "message: " + message); Intent intent = new Intent(); intent.setClassName(ctx, "org.eclipse.paho.android.service.sample.MainActivity"); intent.putExtra("handle", clientHandle); String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) ctx.getSystemService(ns); int messageNotificationId = 1; mNotificationManager.cancel(messageNotificationId); Calendar.getInstance().getTime().toString(); long when = System.currentTimeMillis(); String ticker = sender + " " + mqttMessageValue; PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 3, intent, 0); NotificationCompat.Builder notificationCompat = new NotificationCompat.Builder(ctx); notificationCompat.setAutoCancel(true).setContentTitle(sender).setContentIntent(pendingIntent) .setContentText(mqttMessageValue).setTicker(ticker).setWhen(when) .setSmallIcon(R.drawable.ic_launcher); // Notification notification = notificationCompat.build(); Bitmap iconLarge = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_launcher); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx) .setSmallIcon(R.drawable.ic_launcher).setLargeIcon(iconLarge).setContentTitle(sender) .setContentText(mqttMessageValue); mBuilder.setContentIntent(pendingIntent); mBuilder.setTicker(message); mBuilder.setAutoCancel(true); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS); mNotificationManager.notify(messageNotificationId, mBuilder.build()); }