private void doNotify( Intent i, String contentTitle, List<Message> messages, int notificationCode, boolean withSound) { PendingIntent contentIntent = PendingIntent.getActivity(mContext, notificationCode, i, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(contentTitle) .setTicker(messages.get(0).getContent()) .setContentText(messages.get(0).getContent()); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String[] lastMessages = new String[Math.min(messages.size(), MAX_MESSAGES_PER_GROUP)]; inboxStyle.setBigContentTitle(contentTitle); for (int j = 0; j < lastMessages.length; j++) { inboxStyle.addLine(messages.get(j).getContent()); } builder.setStyle(inboxStyle); builder.setNumber(messages.size()); builder.setContentIntent(contentIntent); builder.setAutoCancel(true); mNotificationManager.notify(notificationCode, builder.build()); if (withSound) { mSoundEffectsPool.play(newMessageSoundId, 1.0f, 1.0f, 0, 0, 1); } }
public void showChatNotification() { if (unreadMessages.size() == 0) return; Message lastMessage = unreadMessages.get(unreadMessages.size() - 1); mStatusNotificationBuilder.setTicker( ((lastMessage.actor != null && lastMessage.actor.name != null) ? lastMessage.actor.name : getString(R.string.server)) + ": " + Html.fromHtml(lastMessage.message).toString()); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); for (Message message : unreadMessages) { inboxStyle.addLine( ((message.actor != null && message.actor.name != null) ? message.actor.name : getString(R.string.server)) + ": " + Html.fromHtml(message.message).toString()); // Escapes // HTML } mStatusNotificationBuilder.setStyle(inboxStyle); Notification notificationCompat = mStatusNotificationBuilder.build(); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(STATUS_NOTIFICATION_ID, notificationCompat); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void notifyMe(String titulo, String message) { counter++; NotificationCompat.Builder mNotifyBuilder; NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); mNotifyBuilder = new NotificationCompat.Builder(this) .setContentTitle(titulo) .setContentText(message) .setSmallIcon(R.mipmap.ic_launcher) .setDefaults(Notification.DEFAULT_SOUND) .setNumber(counter) .setAutoCancel(true); mNotifyBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); mNotificationManager.notify(NOTIFY_ME_ID, mNotifyBuilder.build()); Intent intent = new Intent(this, HomeActivity.class); intent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(HomeActivity.class); stackBuilder.addNextIntent(intent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mNotifyBuilder.setContentIntent(resultPendingIntent); mNotificationManager.notify(NOTIFY_ME_ID, mNotifyBuilder.build()); }
/** Notifies the user that a backup was made */ private void onBackupComplete() { CharSequence noticeText = "Translations backed up"; // activity to open when clicked // TODO: instead of the home activity we need a backup activity where the user can view their // backups. Intent notificationIntent = new Intent(getApplicationContext(), HomeActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); // build notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_notify_msg) .setContentTitle(noticeText) .setAutoCancel(true) .setContentIntent(intent) .setNumber(0); // build big notification NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(noticeText); mBuilder.setStyle(inboxStyle); // issue notification NotificationManager mNotifyMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mNotifyMgr.notify(0, mBuilder.build()); } else { mNotifyMgr.notify(0, mBuilder.getNotification()); } }
protected Notification getNotification(Context context, Intent intent) { JSONObject pushData = getPushData(intent); if (pushData == null || (!pushData.has("alert") && !pushData.has("title"))) { return null; } String title = pushData.optString("title", getDisplayName(context)); String alert = pushData.optString("alert", "Notification received."); String tickerText = String.format(Locale.getDefault(), "%s: %s", title, alert); Bundle extras = intent.getExtras(); if (pushData.has("def")) { extras.putString(Constant.APP_DEF_TAB, pushData.optString("def", null)); } Random random = new Random(); int contentIntentRequestCode = random.nextInt(); int deleteIntentRequestCode = random.nextInt(); // Security consideration: To protect the app from tampering, we require that intent filters // not be exported. To protect the app from information leaks, we restrict the packages which // may intercept the push intents. String packageName = context.getPackageName(); Intent contentIntent = new Intent(ParsePushBroadcastReceiver.ACTION_PUSH_OPEN); contentIntent.putExtras(extras); contentIntent.setPackage(packageName); Intent deleteIntent = new Intent(ParsePushBroadcastReceiver.ACTION_PUSH_DELETE); deleteIntent.putExtras(extras); deleteIntent.setPackage(packageName); PendingIntent pContentIntent = PendingIntent.getBroadcast( context, contentIntentRequestCode, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pDeleteIntent = PendingIntent.getBroadcast( context, deleteIntentRequestCode, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT); // The purpose of setDefaults(Notification.DEFAULT_ALL) is to inherit notification properties // from system defaults NotificationCompat.Builder parseBuilder = new NotificationCompat.Builder(context); parseBuilder .setContentTitle(title) .setContentText(alert) .setTicker(tickerText) .setSmallIcon(this.getSmallIconId(context, intent)) .setLargeIcon(getLargeIcon(context)) .setContentIntent(pContentIntent) .setDeleteIntent(pDeleteIntent) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL); if (alert != null && alert.length() > ParsePushBroadcastReceiver.SMALL_NOTIFICATION_MAX_CHARACTER_LIMIT) { parseBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(alert)); } return parseBuilder.build(); }
public static void showNotActivatedNotification(String packageName, String appName) { Intent intent = new Intent(sContext, WelcomeActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("fragment", 1); PendingIntent pModulesTab = PendingIntent.getActivity( sContext, PENDING_INTENT_OPEN_MODULES, intent, PendingIntent.FLAG_UPDATE_CURRENT); String title = sContext.getString(R.string.module_is_not_activated_yet); NotificationCompat.Builder builder = new NotificationCompat.Builder(sContext) .setContentTitle(title) .setContentText(appName) .setTicker(title) .setContentIntent(pModulesTab) .setVibrate(new long[] {0}) .setAutoCancel(true) .setSmallIcon(R.drawable.ic_notification) .setColor(sContext.getResources().getColor(R.color.colorPrimary)); if (Build.VERSION.SDK_INT >= 21) builder.setPriority(2); Intent iActivateAndReboot = new Intent(sContext, RebootReceiver.class); iActivateAndReboot.putExtra(RebootReceiver.EXTRA_ACTIVATE_MODULE, packageName); PendingIntent pActivateAndReboot = PendingIntent.getBroadcast( sContext, PENDING_INTENT_ACTIVATE_MODULE_AND_REBOOT, iActivateAndReboot, PendingIntent.FLAG_UPDATE_CURRENT); Intent iActivate = new Intent(sContext, RebootReceiver.class); iActivate.putExtra(RebootReceiver.EXTRA_ACTIVATE_MODULE, packageName); iActivate.putExtra(RebootReceiver.EXTRA_ACTIVATE_MODULE_AND_RETURN, true); PendingIntent pActivate = PendingIntent.getBroadcast( sContext, PENDING_INTENT_ACTIVATE_MODULE, iActivate, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.BigTextStyle notiStyle = new NotificationCompat.BigTextStyle(); notiStyle.setBigContentTitle(title); notiStyle.bigText(sContext.getString(R.string.module_is_not_activated_yet_detailed, appName)); builder.setStyle(notiStyle); // Only show the quick activation button if any module has been // enabled before, // to ensure that the user know the way to disable the module later. if (!ModuleUtil.getInstance().getEnabledModules().isEmpty()) { builder.addAction( R.drawable.ic_menu_refresh, sContext.getString(R.string.activate_and_reboot), pActivateAndReboot); builder.addAction(R.drawable.ic_save, sContext.getString(R.string.activate_only), pActivate); } sNotificationManager.notify( packageName, NOTIFICATION_MODULE_NOT_ACTIVATED_YET, builder.build()); }
public void setBigView(String title, String[] contents) { NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(title); for (String content : contents) { inboxStyle.addLine(content); } builder.setStyle(inboxStyle); }
private void showError(String text, String message) { if (!mShowNotifications) return; NotificationCompat.Builder builder = NotificationUtils.createNotificationBuilder(mContext, R.string.sync_notification_title) .setContentText(text); if (!TextUtils.isEmpty(message)) { builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message).setSummaryText(text)); } NotificationUtils.notify(mContext, NotificationUtils.ID_SYNC_ERROR, builder); }
// 发送一个大通知 private NotificationCompat.Builder sendMultipleNotification(NotificationCompat.Builder builder) { // 4.1之前的使用这个,4.1之后的使用下面那个 NotificationCompat.InboxStyle indexStyle = new NotificationCompat.InboxStyle(); // Notification.InboxStyle indexStyle = new Notification.InboxStyle();a indexStyle.setBigContentTitle("大广播"); String event[] = {"事件1", "事件2", "事件3"}; for (int i = 0; i < event.length; i++) { indexStyle.addLine(event[i]); } builder.setStyle(indexStyle); return builder; }
private static Notification buildNotification( Context context, boolean playSound, boolean useLights, int icon, String message, NotificationCompat.InboxStyle bigTextStyle) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Resources res = context.getResources(); String title = res.getString(R.string.app_name); int defaults = 0; // Build the compatible notification NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title).setAutoCancel(true); if (useLights) builder.setLights(0xffff6000, 500, 1000); builder.setSmallIcon(icon); if (playSound) { String ringtone = prefs.getString("notifications_new_message_ringtone", null); Uri ringtoneUri = null; if (ringtone == null) { ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } else { ringtoneUri = Uri.parse(ringtone); } builder.setSound(ringtoneUri); // Vibrate only if we are playing a sound if (prefs.getBoolean("notifications_new_message_vibrate", true)) { defaults |= Notification.DEFAULT_VIBRATE; } } builder.setContentText(message); if (bigTextStyle != null) { builder.setStyle(bigTextStyle); } builder.setDefaults(defaults); // Creates an explicit intent for ChatActivity Intent resultIntent = new Intent(context, ChatActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); resultIntent.setAction("android.intent.action.MAIN"); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); return builder.build(); }
public void clearChatNotification() { if (unreadMessages == null || mStatusNotificationBuilder == null) return; unreadMessages.clear(); mStatusNotificationBuilder.setTicker(null); mStatusNotificationBuilder.setStyle(null); Notification notificationCompat = mStatusNotificationBuilder.build(); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(STATUS_NOTIFICATION_ID, notificationCompat); }
public void createNewNotification(String title, String content) { initBuilder(title, content); initBigTextStyle(title, content); builder.setStyle(bigTextStyle); initNotificationIntent(); initExitNavigationIntent(); initStackBuilder(notificationIntent); builder.addAction(R.drawable.ic_dismiss, "Exit Navigation", pendingExitNavigationIntent); builder.setContentIntent( pendingNotificationIntent.getActivity( baseActivity.getApplicationContext(), 0, notificationIntent, 0)); mNotificationManager.notify("route", 0, builder.build()); }
private void sendBigViewNotification() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(activity) .setSmallIcon(R.drawable.ic_media_play) .setContentTitle("Test Big") .setContentText("text big!!!!"); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle("You have many messages"); inboxStyle.addLine("msg1"); inboxStyle.addLine("msg2"); mBuilder.setStyle(inboxStyle); NotificationManager mNotificationManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(TEST_NOTIF_ID, mBuilder.build()); }
private void showNotification() { mNotifMGR = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); // notification for the task bar NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_music); builder.setContentTitle(mArtist[mSong]); builder.setContentText(mTitle[mSong]); builder.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), mArtwork[mSong])); builder.setAutoCancel(false); builder.setOngoing(true); NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle(); style.setBigContentTitle(mArtist[mSong]); style.setSummaryText(mTitle[mSong]); style.bigLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_music)); style.bigPicture(BitmapFactory.decodeResource(this.getResources(), mArtwork[mSong])); builder.setStyle(style); Intent skipIntent = new Intent(PREV_TRACK); PendingIntent pIntent = PendingIntent.getBroadcast(this, 0, skipIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(android.R.drawable.ic_media_rew, "Last Track", pIntent); skipIntent = new Intent(NEXT_TRACK); pIntent = PendingIntent.getBroadcast(this, 0, skipIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(android.R.drawable.ic_media_ff, "Next Track", pIntent); Intent clickIntent = new Intent(this, MainActivity.class); clickIntent.putExtra(MainFragment.EXTRA_TITLE_UPDATE, mTitle[mSong]); clickIntent.putExtra(MainFragment.EXTRA_COVER_UPDATE, mArtwork[mSong]); clickIntent.putExtra(MainFragment.EXTRA_ARTIST_UPDATE, mArtist[mSong]); clickIntent.putExtra(MainFragment.EXTRA_SONG_DURATION, mPlayer.getDuration()); PendingIntent pendClickIntent = PendingIntent.getActivity(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendClickIntent); Notification notification = builder.build(); startForeground(NOTIF_ID, notification); }
private Notification getNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder .setSmallIcon(R.drawable.ic_stat_notify_24dp) .setColor(getResources().getColor(R.color.primary)) .setContentTitle( getResources() .getQuantityString( R.plurals.passp_cache_notif_n_keys, mPassphraseCache.size(), mPassphraseCache.size())) .setContentText(getString(R.string.passp_cache_notif_touch_to_clear)); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(getString(R.string.passp_cache_notif_keys)); // Moves events into the big view for (int i = 0; i < mPassphraseCache.size(); i++) { inboxStyle.addLine(mPassphraseCache.valueAt(i).mPrimaryUserId); } // Moves the big view style object into the notification object. builder.setStyle(inboxStyle); Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class); intent.setAction(ACTION_PASSPHRASE_CACHE_CLEAR); PendingIntent clearCachePi = PendingIntent.getService( getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Add cache clear PI to normal touch builder.setContentIntent(clearCachePi); // Add clear PI action below text builder.addAction( R.drawable.ic_close_white_24dp, getString(R.string.passp_cache_notif_clear), clearCachePi); return builder.build(); }
/** Notification 띄어주는 클래스 */ private void sendNotification(String title, String message) { Intent intent = new Intent(this, MapActivity.class); // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, REQUEST_CODE, intent, PendingIntent.FLAG_ONE_SHOT); // Bitmap Bitmap picture = BitmapFactory.decodeResource(getResources(), R.drawable.r2d2_24logo); Bitmap picture2 = BitmapFactory.decodeResource(getResources(), R.drawable.r2d2icon); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.r2d2_24logo) .setContentTitle(title) .setContentText(message) .setSound(defaultSoundUri) // - EXPANDED DEFAULT // .setPriority(NotificationCompat.PRIORITY_MAX) .setContentIntent(pendingIntent); NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle(notificationBuilder); style .bigLargeIcon(picture) .bigPicture(picture2) .setBigContentTitle("R2D2") .setSummaryText("주인님!! 맛집 정보입니다!!"); notificationBuilder.setStyle(style); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); }
@Override public Notification buildNotification(Context context, FollowsChecker followsChecker) { Resources r = context.getResources(); matchKey = match.getKey(); String matchTitle = MatchHelper.getMatchTitleFromMatchKey(context, matchKey); String matchAbbrevTitle = MatchHelper.getAbbrevMatchTitleFromMatchKey(context, matchKey); JsonObject alliances = match.getAlliancesJson(); int redScore = Match.getRedScore(alliances); int blueScore = Match.getBlueScore(alliances); // Boldify the team numbers that the user is following. Predicate<String> isFollowing = teamNumber -> followsChecker.followsTeam( context, teamNumber, matchKey, NotificationTypes.MATCH_SCORE); ArrayList<String> redTeams = Match.teamNumbers(Match.getRedTeams(alliances)); ArrayList<String> blueTeams = Match.teamNumbers(Match.getBlueTeams(alliances)); CharSequence firstTeams = Utilities.boldNameList(redTeams, isFollowing); CharSequence secondTeams = Utilities.boldNameList(blueTeams, isFollowing); // Make sure the score string is formatted properly with the winning score first String scoreString; if (blueScore > redScore) { scoreString = blueScore + "-" + redScore; CharSequence temp = firstTeams; firstTeams = secondTeams; secondTeams = temp; } else { scoreString = redScore + "-" + blueScore; } MatchType matchType = MatchType.fromShortType(match.getCompLevel()); boolean useSpecial2015Format = match.getYear() == 2015 && matchType != MatchType.FINAL; String eventShortName = EventHelper.shortName(eventName); String template; if (useSpecial2015Format) { // firstTeams played secondTeams (for 2015 non-finals matches) template = context.getString(R.string.notification_score_teams_played_teams); } else if (blueScore == redScore) { // firstTeams tied secondTeams template = context.getString(R.string.notification_score_teams_tied_teams); } else { // firstTeams beat secondTeams template = context.getString(R.string.notification_score_teams_beat_teams); } CharSequence notificationBody = TextUtils.expandTemplate( template, eventShortName, matchTitle, firstTeams, secondTeams, scoreString); // We can finally build the notification! Intent instance = getIntent(context); stored = new StoredNotification(); stored.setType(getNotificationType()); String eventCode = EventHelper.getEventCode(matchKey); String notificationTitle = r.getString(R.string.notification_score_title, eventCode, matchAbbrevTitle); stored.setTitle(notificationTitle); stored.setBody(notificationBody.toString()); stored.setIntent(MyTBAHelper.serializeIntent(instance)); stored.setTime(Calendar.getInstance().getTime()); stored.setMessageData(messageData); NotificationCompat.Builder builder = getBaseBuilder(context, instance) .setContentTitle(notificationTitle) .setContentText(notificationBody); NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle().bigText(notificationBody); builder.setStyle(style); return builder.build(); }
private void setNotificationMessage( int notId, Bundle extras, NotificationCompat.Builder mBuilder) { String message = extras.getString(MESSAGE); String style = extras.getString(STYLE, STYLE_TEXT); if (STYLE_INBOX.equals(style)) { setNotification(notId, message); mBuilder.setContentText(fromHtml(message)); ArrayList<String> messageList = messageMap.get(notId); Integer sizeList = messageList.size(); if (sizeList > 1) { String sizeListMessage = sizeList.toString(); String stacking = sizeList + " more"; if (extras.getString(SUMMARY_TEXT) != null) { stacking = extras.getString(SUMMARY_TEXT); stacking = stacking.replace("%n%", sizeListMessage); } NotificationCompat.InboxStyle notificationInbox = new NotificationCompat.InboxStyle() .setBigContentTitle(fromHtml(extras.getString(TITLE))) .setSummaryText(fromHtml(stacking)); for (int i = messageList.size() - 1; i >= 0; i--) { notificationInbox.addLine(fromHtml(messageList.get(i))); } mBuilder.setStyle(notificationInbox); } else { NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle(); if (message != null) { bigText.bigText(fromHtml(message)); bigText.setBigContentTitle(fromHtml(extras.getString(TITLE))); mBuilder.setStyle(bigText); } } } else if (STYLE_PICTURE.equals(style)) { setNotification(notId, ""); NotificationCompat.BigPictureStyle bigPicture = new NotificationCompat.BigPictureStyle(); bigPicture.bigPicture(getBitmapFromURL(extras.getString(PICTURE))); bigPicture.setBigContentTitle(fromHtml(extras.getString(TITLE))); bigPicture.setSummaryText(fromHtml(extras.getString(SUMMARY_TEXT))); mBuilder.setContentTitle(fromHtml(extras.getString(TITLE))); mBuilder.setContentText(fromHtml(message)); mBuilder.setStyle(bigPicture); } else { setNotification(notId, ""); NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle(); if (message != null) { mBuilder.setContentText(fromHtml(message)); bigText.bigText(fromHtml(message)); bigText.setBigContentTitle(fromHtml(extras.getString(TITLE))); String summaryText = extras.getString(SUMMARY_TEXT); if (summaryText != null) { bigText.setSummaryText(fromHtml(summaryText)); } mBuilder.setStyle(bigText); } /* else { mBuilder.setContentText("<missing message content>"); } */ } }
public void postNotification(int id) { if (notificationItems.size() == 0) { return; } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setContentTitle(notificationTitle); mBuilder.setSmallIcon(R.drawable.ic_stat_icon); mBuilder.setLargeIcon( BitmapFactory.decodeResource( context.getResources(), R.drawable.ic_action_notification_dark)); if (notificationItems.size() > 1) { // inbox style NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle(); try { inbox.setBigContentTitle(notificationTitle); } catch (Exception e) { } if (notificationItems.size() <= 5) { for (String s : notificationItems) { inbox.addLine(Html.fromHtml(s)); } } else { for (int i = 0; i < 5; i++) { inbox.addLine(Html.fromHtml(notificationItems.get(i))); } int extra = notificationItems.size() - 5; if (extra > 1) { inbox.setSummaryText("+" + extra + " " + context.getString(R.string.items)); } else { inbox.setSummaryText("+" + extra + " " + context.getString(R.string.item)); } } mBuilder.setStyle(inbox); mBuilder.setContentText(notificationItems.size() + " " + context.getString(R.string.items)); } else { // big text style NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle(); bigText.bigText(Html.fromHtml(notificationItems.get(0))); bigText.setBigContentTitle(notificationTitle); mBuilder.setStyle(bigText); mBuilder.setContentText(Html.fromHtml(notificationItems.get(0))); } if (!useSecondAccount) { mBuilder.setContentIntent( PendingIntent.getActivity(context, 0, new Intent(context, RedirectToActivity.class), 0)); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) { mBuilder.setLights(0xFFFFFF, 1000, 1000); } if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock( (PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { NotificationUtils.sendAlertToPebble(context, notificationTitle, notificationItems.get(0)); } // Light Flow notification NotificationUtils.sendToLightFlow(context, notificationTitle, notificationItems.get(0)); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(id, mBuilder.build()); }
public static void showNotification( Context context, Updater.PackageInfo[] infosRom, Updater.PackageInfo[] infosGapps) { Resources resources = context.getResources(); if (infosRom != null) { sPackageInfosRom = infosRom; } else { infosRom = sPackageInfosRom; } if (infosGapps != null) { sPackageInfosGapps = infosGapps; } else { infosGapps = sPackageInfosGapps; } int contentTitleResourceId = -1; if (infosRom.length > 0 && infosGapps.length > 0) { contentTitleResourceId = !Utils.weAreInBS() ? R.string.update_all_to_bs : R.string.new_all_found_title; } else if (infosRom.length == 0) { contentTitleResourceId = !Utils.weAreInBS() ? R.string.update_gapps_to_bs : R.string.new_gapps_found_title; } else { contentTitleResourceId = !Utils.weAreInBS() ? R.string.update_rom_to_bs : R.string.new_rom_found_title; } Intent intent = new Intent(context, MainActivity.class); NotificationInfo fileInfo = new NotificationInfo(); fileInfo.mNotificationId = Updater.NOTIFICATION_ID; fileInfo.mPackageInfosRom = infosRom; fileInfo.mPackageInfosGapps = infosGapps; intent.putExtra(FILES_INFO, fileInfo); PendingIntent pIntent = PendingIntent.getActivity( context, Updater.NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentTitle(resources.getString(contentTitleResourceId)) .setSmallIcon(R.drawable.ic_launcher) .setContentIntent(pIntent); String contextText = ""; if (infosRom.length + infosGapps.length == 1) { String filename = infosRom.length == 1 ? infosRom[0].getFilename() : infosGapps[0].getFilename(); contextText = resources.getString(R.string.new_package_name, new Object[] {filename}); } else { contextText = resources.getString( R.string.new_packages, new Object[] {infosRom.length + infosGapps.length}); } builder.setContentText(contextText); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(context.getResources().getString(contentTitleResourceId)); if (infosRom.length + infosGapps.length > 1) { inboxStyle.addLine(contextText); } for (int i = 0; i < infosRom.length; i++) { inboxStyle.addLine(infosRom[i].getFilename()); } for (int i = 0; i < infosGapps.length; i++) { inboxStyle.addLine(infosGapps[i].getFilename()); } builder.setStyle(inboxStyle); Notification notif = builder.build(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE); notif.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(Updater.NOTIFICATION_ID, notif); }
@NonNull public static Notification buildNotification( @NonNull Context context, final int id, @NonNull Object... objects) { final Resources res = context.getResources(); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.stat_acdisplay) .setColor(App.ACCENT_COLOR) .setAutoCancel(true); PendingIntent pi = null; switch (id) { case App.ID_NOTIFY_TEST: { NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(res.getString(R.string.notification_test_message_large)); builder .setStyle(bts) .setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.notification_test_message)) .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); break; } case App.ID_NOTIFY_BATH: { CharSequence contentText = (CharSequence) objects[0]; Intent contentIntent = (Intent) objects[1]; // Build notification pi = PendingIntent.getActivity( context, id, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder .setContentTitle(res.getString(R.string.service_bath)) .setContentText(contentText) .setPriority(Notification.PRIORITY_MIN); break; } case App.ID_NOTIFY_INIT: { builder .setSmallIcon(R.drawable.stat_notify) .setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.notification_init_text)) .setPriority(Notification.PRIORITY_MIN); break; } case App.ID_NOTIFY_APP_AUTO_DISABLED: { CharSequence summary = (CharSequence) objects[0]; NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(res.getString(R.string.permissions_auto_disabled)) .setSummaryText(summary); builder .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher)) .setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.permissions_auto_disabled)) .setPriority(Notification.PRIORITY_HIGH) .setStyle(bts); break; } default: throw new IllegalArgumentException(); } if (pi == null) { pi = PendingIntent.getActivity( context, id, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); } return builder.setContentIntent(pi).build(); }
public void showNotifications(List<String> contacts) { if (!(ActivityMonitor.getInstance().getCurrentActivity() instanceof ConversationsActivity)) { Conversation[] conversations = Database.getInstance(applicationContext).getConversations(preferences.getDid()); for (Conversation conversation : conversations) { if (!conversation.isUnread() || !contacts.contains(conversation.getContact()) || (ActivityMonitor.getInstance().getCurrentActivity() instanceof ConversationActivity && ((ConversationActivity) ActivityMonitor.getInstance().getCurrentActivity()) .getContact() .equals(conversation.getContact()))) { continue; } String smsContact = Utils.getContactName(applicationContext, conversation.getContact()); if (smsContact == null) { smsContact = Utils.getFormattedPhoneNumber(conversation.getContact()); } String allSmses = ""; String mostRecentSms = ""; boolean initial = true; for (Message message : conversation.getMessages()) { if (message.getType() == Message.Type.INCOMING && message.isUnread()) { if (initial) { allSmses = message.getText(); mostRecentSms = message.getText(); initial = false; } else { allSmses = message.getText() + "\n" + allSmses; } } else { break; } } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(applicationContext); notificationBuilder.setContentTitle(smsContact); notificationBuilder.setContentText(mostRecentSms); notificationBuilder.setSmallIcon(R.drawable.ic_chat_white_24dp); notificationBuilder.setPriority(Notification.PRIORITY_HIGH); notificationBuilder.setSound( Uri.parse(Preferences.getInstance(applicationContext).getNotificationSound())); notificationBuilder.setLights(0xFFAA0000, 1000, 5000); if (Preferences.getInstance(applicationContext).getNotificationVibrateEnabled()) { notificationBuilder.setVibrate(new long[] {0, 250, 250, 250}); } else { notificationBuilder.setVibrate(new long[] {0}); } notificationBuilder.setColor(0xFFAA0000); notificationBuilder.setAutoCancel(true); notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(allSmses)); Bitmap largeIconBitmap; try { largeIconBitmap = MediaStore.Images.Media.getBitmap( applicationContext.getContentResolver(), Uri.parse( Utils.getContactPhotoUri(applicationContext, conversation.getContact()))); largeIconBitmap = Bitmap.createScaledBitmap(largeIconBitmap, 256, 256, false); largeIconBitmap = Utils.applyCircularMask(largeIconBitmap); notificationBuilder.setLargeIcon(largeIconBitmap); } catch (Exception ignored) { } Intent intent = new Intent(applicationContext, ConversationActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra( applicationContext.getString(R.string.conversation_extra_contact), conversation.getContact()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(applicationContext); stackBuilder.addParentStack(ConversationActivity.class); stackBuilder.addNextIntent(intent); notificationBuilder.setContentIntent( stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT)); Intent replyIntent = new Intent(applicationContext, ConversationQuickReplyActivity.class); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { replyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); } else { //noinspection deprecation replyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); } replyIntent.putExtra( applicationContext.getString(R.string.conversation_extra_contact), conversation.getContact()); PendingIntent replyPendingIntent = PendingIntent.getActivity( applicationContext, 0, replyIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action.Builder replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_white_24dp, applicationContext.getString(R.string.notifications_button_reply), replyPendingIntent); notificationBuilder.addAction(replyAction.build()); Intent markAsReadIntent = new Intent(applicationContext, MarkAsReadReceiver.class); markAsReadIntent.putExtra( applicationContext.getString(R.string.conversation_extra_contact), conversation.getContact()); PendingIntent markAsReadPendingIntent = PendingIntent.getBroadcast( applicationContext, 0, markAsReadIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action.Builder markAsReadAction = new NotificationCompat.Action.Builder( R.drawable.ic_drafts_white_24dp, applicationContext.getString(R.string.notifications_button_mark_read), markAsReadPendingIntent); notificationBuilder.addAction(markAsReadAction.build()); int id; if (notificationIds.get(conversation.getContact()) != null) { id = notificationIds.get(conversation.getContact()); } else { id = notificationIdCount++; notificationIds.put(conversation.getContact(), id); } NotificationManager notificationManager = (NotificationManager) applicationContext.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(id, notificationBuilder.build()); } } }
@Override public Builder setStyle(NotificationCompat.Style style) { super.setStyle(style); return this; }
private void onNotify( final SharedPreferences prefs, final Cursor upcomingEpisodes, int count, long latestAirtime) { final Context context = getApplicationContext(); CharSequence tickerText = ""; CharSequence contentTitle = ""; CharSequence contentText = ""; PendingIntent contentIntent = null; // notification sound final String ringtoneUri = NotificationSettings.getNotificationsRingtone(context); // vibration final boolean isVibrating = NotificationSettings.isNotificationVibrating(context); if (count == 1) { // notify in detail about one episode upcomingEpisodes.moveToFirst(); final String showTitle = upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE); final String airs = Utils.formatToTimeAndDay(upcomingEpisodes.getLong(NotificationQuery.FIRSTAIREDMS), this)[ 0]; final String network = upcomingEpisodes.getString(NotificationQuery.NETWORK); tickerText = getString(R.string.upcoming_show, showTitle); contentTitle = showTitle + " " + Utils.getEpisodeNumber( this, upcomingEpisodes.getInt(NotificationQuery.SEASON), upcomingEpisodes.getInt(NotificationQuery.NUMBER)); contentText = getString(R.string.upcoming_show_detailed, airs, network); Intent notificationIntent = new Intent(context, EpisodesActivity.class); notificationIntent.putExtra( EpisodesActivity.InitBundle.EPISODE_TVDBID, upcomingEpisodes.getInt(NotificationQuery._ID)); notificationIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime); contentIntent = PendingIntent.getActivity(context, REQUEST_CODE_SINGLE_EPISODE, notificationIntent, 0); } else if (count > 1) { // notify about multiple episodes tickerText = getString(R.string.upcoming_episodes); contentTitle = getString(R.string.upcoming_episodes_number, count); contentText = getString(R.string.upcoming_display); Intent notificationIntent = new Intent(context, UpcomingRecentActivity.class); notificationIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime); contentIntent = PendingIntent.getActivity(context, REQUEST_CODE_MULTIPLE_EPISODES, notificationIntent, 0); } final NotificationCompat.Builder nb = new NotificationCompat.Builder(context); if (AndroidUtils.isJellyBeanOrHigher()) { // JELLY BEAN and above if (count == 1) { // single episode upcomingEpisodes.moveToFirst(); final String imagePath = upcomingEpisodes.getString(NotificationQuery.POSTER); nb.setLargeIcon(ImageProvider.getInstance(context).getImage(imagePath, true)); final String episodeTitle = upcomingEpisodes.getString(NotificationQuery.TITLE); final String episodeSummary = upcomingEpisodes.getString(NotificationQuery.OVERVIEW); final SpannableStringBuilder bigText = new SpannableStringBuilder(); bigText.append(episodeTitle); bigText.setSpan(new ForegroundColorSpan(Color.WHITE), 0, bigText.length(), 0); bigText.append("\n"); bigText.append(episodeSummary); nb.setStyle( new NotificationCompat.BigTextStyle().bigText(bigText).setSummaryText(contentText)); // Action button to check in Intent checkInActionIntent = new Intent(context, QuickCheckInActivity.class); checkInActionIntent.putExtra( QuickCheckInActivity.InitBundle.EPISODE_TVDBID, upcomingEpisodes.getInt(NotificationQuery._ID)); PendingIntent checkInIntent = PendingIntent.getActivity(context, REQUEST_CODE_ACTION_CHECKIN, checkInActionIntent, 0); nb.addAction(R.drawable.ic_action_checkin, getString(R.string.checkin), checkInIntent); } else { // multiple episodes NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // display at most the first five final int displayCount = Math.min(count, 5); for (int i = 0; i < displayCount; i++) { if (upcomingEpisodes.moveToPosition(i)) { // add show title, air time and network final SpannableStringBuilder lineText = new SpannableStringBuilder(); lineText.append(upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE)); lineText.setSpan(new ForegroundColorSpan(Color.WHITE), 0, lineText.length(), 0); lineText.append(" "); String airs = Utils.formatToTimeAndDay( upcomingEpisodes.getLong(NotificationQuery.FIRSTAIREDMS), this)[0]; String network = upcomingEpisodes.getString(NotificationQuery.NETWORK); lineText.append(getString(R.string.upcoming_show_detailed, airs, network)); inboxStyle.addLine(lineText); } } // tell if we could not display all episodes if (count > 5) { inboxStyle.setSummaryText(getString(R.string.more, count - 5)); } nb.setStyle(inboxStyle); nb.setContentInfo(String.valueOf(count)); } } else { // ICS and below if (count == 1) { // single episode upcomingEpisodes.moveToFirst(); final String posterPath = upcomingEpisodes.getString(NotificationQuery.POSTER); nb.setLargeIcon(ImageProvider.getInstance(context).getImage(posterPath, true)); } } // If the string is empty, the user chose silent... if (ringtoneUri.length() != 0) { // ...otherwise set the specified ringtone nb.setSound(Uri.parse(ringtoneUri)); } if (isVibrating) { nb.setVibrate(VIBRATION_PATTERN); } nb.setDefaults(Notification.DEFAULT_LIGHTS); nb.setWhen(System.currentTimeMillis()); nb.setAutoCancel(true); nb.setTicker(tickerText); nb.setContentTitle(contentTitle); nb.setContentText(contentText); nb.setContentIntent(contentIntent); nb.setSmallIcon(R.drawable.ic_notification); nb.setPriority(NotificationCompat.PRIORITY_DEFAULT); Intent i = new Intent(this, NotificationService.class); i.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime); PendingIntent deleteIntent = PendingIntent.getService(this, 1, i, 0); nb.setDeleteIntent(deleteIntent); // build the notification Notification notification = nb.build(); // use string resource id, always unique within app final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(R.string.upcoming_show, notification); }
@Override public void onReceive(Context context, Intent intent) { Log.v(TAG, intent.toString()); session = Session.getInstance(context); String action = intent.getAction(); Bundle data = intent.getExtras(); final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationCompat.Builder ncb; if (action.equals(Intent.ACTION_BOOT_COMPLETED)) { session.registerAlarms(); } else if (action.equals(SR.CLEAN_DB_CACHE) || action.equals(SR.GDRIVE_SYNCNOW) || action.equals(SR.CHECK_TVDB_RSS)) { session.registerAlarms(); WakefulIntentService.sendWakefulWork( context, new Intent(context, Service.class).setAction(action)); } else if (action.equals(SN.CONNECT_FAIL)) { ncb = new NotificationCompat.Builder(session.getContext()).setAutoCancel(true); ncb.setSmallIcon(R.drawable.ic_notification_error); ncb.setContentTitle(session.getString(R.string.notif_gac_fail)); ncb.setContentIntent(newPI(newAI(SN.CONNECT_FAIL), false)); if (session.notificationSound()) ncb.setSound(NOTIF_SOUND); nm.notify(NOTIF_CONNECT_FAIL, ncb.build()); } else if (action.equals(Commons.SN.GENERAL_FAIL)) { ncb = new NotificationCompat.Builder(session.getContext()).setAutoCancel(true); ncb.setSmallIcon(R.drawable.ic_notification_error); ncb.setContentTitle(session.getString(R.string.notif_srv_fail)); ncb.setContentText(data.getString("what")); ncb.setContentIntent(newPI(newAI(SN.GENERAL_FAIL), false)); if (session.notificationSound()) ncb.setSound(NOTIF_SOUND); nm.notify(NOTIF_GENERAL_FAIL, ncb.build()); } else if (action.equals(Commons.SN.GENERAL_INFO)) { ncb = new NotificationCompat.Builder(session.getContext()).setAutoCancel(true); ncb.setSmallIcon(R.drawable.ic_notification_info); ncb.setContentTitle(session.getString(R.string.notif_srv_info)); ncb.setContentText(data.getString("what")); ncb.setContentIntent(newPI(newAI(SN.GENERAL_INFO), false)); if (session.notificationSound()) ncb.setSound(NOTIF_SOUND); nm.notify(NOTIF_GENERAL_INFO, ncb.build()); } else if (action.equals(SN.MOV_WLST)) { ncb = new NotificationCompat.Builder(session.getContext()).setAutoCancel(true); ncb.setSmallIcon(R.drawable.ic_notification_movie); ncb.setContentTitle(session.getString(R.string.notif_mov_wlst)); ncb.setContentText(data.getString("name", session.getString(R.string.notif_gen_miss))); ncb.setContentIntent( newPI(newAI(MA.MOVIE_INFO).putExtra("imdb_id", data.getString("imdb_id")), true)); if (session.notificationSound()) ncb.setSound(NOTIF_SOUND); nm.notify(NOTIF_ID.incrementAndGet(), ncb.build()); } else if (action.equals(SN.MOV_COLL)) { ncb = new NotificationCompat.Builder(session.getContext()).setAutoCancel(true); ncb.setSmallIcon(R.drawable.ic_notification_movie); ncb.setContentTitle(session.getString(R.string.notif_mov_coll)); ncb.setContentText(data.getString("name", session.getString(R.string.notif_gen_miss))); ncb.setContentIntent( newPI(newAI(MA.MOVIE_INFO).putExtra("imdb_id", data.getString("imdb_id")), true)); if (session.notificationSound()) ncb.setSound(NOTIF_SOUND); nm.notify(NOTIF_ID.incrementAndGet(), ncb.build()); } else if (action.equals(SN.SER_WLST)) { ncb = new NotificationCompat.Builder(session.getContext()).setAutoCancel(true); ncb.setSmallIcon(R.drawable.ic_notification_series); ncb.setContentTitle(session.getString(R.string.notif_ser_wlst)); ncb.setContentText(data.getString("name", session.getString(R.string.notif_gen_miss))); ncb.setContentIntent( newPI(newAI(MA.SERIES_INFO).putExtra("tvdb_id", data.getString("tvdb_id")), true)); if (session.notificationSound()) ncb.setSound(NOTIF_SOUND); nm.notify(NOTIF_ID.incrementAndGet(), ncb.build()); } else if (action.equals(SN.SER_COLL)) { EID eid = new EID(data.getString("series"), data.getInt("season"), data.getInt("episode")); ncb = new NotificationCompat.Builder(session.getContext()).setAutoCancel(true); ncb.setSmallIcon(R.drawable.ic_notification_series); ncb.setContentTitle(session.getString(R.string.notif_ser_coll)); ncb.setContentText( eid.readable() + " " + data.getString("name", session.getString(R.string.unknown_title))); ncb.setContentIntent( newPI( newAI(MA.EPISODE_INFO) .putExtra("series", eid.series) .putExtra("season", eid.season) .putExtra("episode", eid.episode), true)); if (session.notificationSound()) ncb.setSound(NOTIF_SOUND); nm.notify(NOTIF_ID.incrementAndGet(), ncb.build()); } else if (action.equals(SN.SER_PREM)) { ncb = new NotificationCompat.Builder(session.getContext()).setAutoCancel(true); ncb.setSmallIcon(R.drawable.ic_notification_premiere); ncb.setContentTitle(session.getString(R.string.notif_ser_prem)); ncb.setContentText(data.getString("name", session.getString(R.string.notif_gen_miss))); ncb.setContentIntent( newPI(newAI(MA.SERIES_INFO).putExtra("tvdb_id", data.getString("tvdb_id")), true)); if (session.notificationSound()) ncb.setSound(NOTIF_SOUND); String plot = data.getString("plot"); if (!TextUtils.isEmpty(plot)) ncb.setStyle(new NotificationCompat.BigTextStyle().bigText(plot)); String purl = data.getString("poster"); if (TextUtils.isEmpty(purl)) nm.notify(NOTIF_ID.incrementAndGet(), ncb.build()); else session .picasso() .load(purl) .placeholder(R.drawable.ic_notification_premiere) .into( new Target() { @Override public void onPrepareLoad(Drawable arg0) {} @Override public void onBitmapLoaded(Bitmap bitmap, LoadedFrom source) { ncb.setLargeIcon(bitmap); nm.notify(NOTIF_ID.incrementAndGet(), ncb.build()); } @Override public void onBitmapFailed(Drawable arg0) { nm.notify(NOTIF_ID.incrementAndGet(), ncb.build()); } }); } else if (action.equals(SN.SER_CANC)) { ncb = new NotificationCompat.Builder(session.getContext()).setAutoCancel(true); ncb.setSmallIcon(R.drawable.ic_notification_deleted); ncb.setContentTitle(session.getString(R.string.notif_ser_canc)); ncb.setContentText(data.getString("name", session.getString(R.string.notif_gen_miss))); ncb.setContentIntent( newPI(newAI(MA.SERIES_INFO).putExtra("tvdb_id", data.getString("tvdb_id")), true)); if (session.notificationSound()) ncb.setSound(NOTIF_SOUND); String purl = data.getString("poster"); if (TextUtils.isEmpty(purl)) nm.notify(NOTIF_ID.incrementAndGet(), ncb.build()); else session .picasso() .load(purl) .placeholder(R.drawable.ic_notification_deleted) .into( new Target() { @Override public void onPrepareLoad(Drawable arg0) {} @Override public void onBitmapLoaded(Bitmap bitmap, LoadedFrom source) { ncb.setLargeIcon(bitmap); nm.notify(NOTIF_ID.incrementAndGet(), ncb.build()); } @Override public void onBitmapFailed(Drawable arg0) { nm.notify(NOTIF_ID.incrementAndGet(), ncb.build()); } }); } else if (action.equals(SN.DBG_TVDB_RSS)) { ncb = new NotificationCompat.Builder(session.getContext()).setAutoCancel(true); ncb.setSmallIcon(R.drawable.ic_notification_info); ncb.setContentTitle(session.getString(R.string.notif_dbg_rsst)); ncb.setContentText( String.format( session.getString(R.string.notif_dbg_rssm), data.getInt("tot"), data.getInt("chk"), data.getInt("oks"))); ncb.setContentIntent(newPI(newAI(SN.GENERAL_INFO), false)); nm.notify(NOTIF_GENERAL_INFO, ncb.build()); } }
private void showNotification( Context context, int notificationId, int smallIconId, String title, String contentText, String bigTitle, String bigContentText, String summaryText, String ticker, Intent intent) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSound(soundUri); if (smallIconId == 0) { builder.setSmallIcon(R.mipmap.ic_launcher); } else { builder.setSmallIcon(smallIconId); } builder.setWhen(System.currentTimeMillis()); // builder.setNumber(10); if (!StringUtils.isEmptyString(ticker)) { builder.setTicker(ticker); } if (StringUtils.isEmptyString(title)) { builder.setContentTitle(PackageUtils.getApplicationName(context)); } else { builder.setContentTitle(title); } builder.setContentText(contentText); builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); builder.setAutoCancel(true); // big title and text if (!StringUtils.isEmptyString(bigTitle) && !StringUtils.isEmptyString(bigContentText)) { NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder); if (!StringUtils.isEmptyString(summaryText)) { style.setSummaryText(summaryText); } style.setBigContentTitle(bigTitle); style.bigText(bigContentText); builder.setStyle(style); } if (intent != null) { intent.setFlags( intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity( context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); } notificationManager.notify(notificationId, builder.build()); }