public static NotificationCompat.Builder getBaseBuilder(Context ctx, boolean setAutoCancel) { Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(ctx); notifBuilder.setSound(defaultSoundUri); notifBuilder.setAutoCancel(setAutoCancel); notifBuilder.setSmallIcon(R.drawable.ic_notification); // Notification styles changed since Lollipop if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { int color; // We have to check the M version for the deprecation of the method getColor() if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { color = ctx.getResources().getColor(R.color.highlight_light); } else { color = ctx.getResources().getColor(R.color.highlight_light); } notifBuilder.setColor(color); } else { // in older versions, we show the App logo notifBuilder.setLargeIcon( BitmapFactory.decodeResource(ctx.getResources(), MobileLearning.APP_LOGO)); } return notifBuilder; }
void handleStart(Intent intent, int startId) { NotificationManager mManager = (NotificationManager) this.getApplicationContext().getSystemService(NOTIFICATION_SERVICE); int id = intent.getIntExtra(IntentStrings.SESSION, 0); String session_timings = intent.getStringExtra(IntentStrings.SESSION_TIMING); DbSingleton dbSingleton = DbSingleton.getInstance(); Session session = dbSingleton.getSessionById(id); Intent intent1 = new Intent(this.getApplicationContext(), SessionDetailActivity.class); intent1.putExtra(IntentStrings.SESSION, session.getTitle()); PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(), 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_bookmark_white_24dp) .setLargeIcon(largeIcon) .setContentTitle(session.getTitle()) .setContentText(session_timings) .setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(session_timings)) .setContentIntent(pendingNotificationIntent); intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); mManager.notify(1, mBuilder.build()); }
/** Creates the notification with all its options passed through JS. */ public Notification build() { Uri sound = options.getSoundUri(); NotificationCompat.BigTextStyle style; NotificationCompat.Builder builder; style = new NotificationCompat.BigTextStyle().bigText(options.getText()); builder = new NotificationCompat.Builder(context) .setDefaults(0) .setContentTitle(options.getTitle()) .setContentText(options.getText()) .setNumber(options.getBadgeNumber()) .setTicker(options.getText()) .setSmallIcon(options.getSmallIcon()) .setLargeIcon(options.getIconBitmap()) .setAutoCancel(true) .setOngoing(options.isOngoing()) .setStyle(style) .setLights(options.getLedColor(), 500, 500); if (sound != null) { builder.setSound(sound); } applyDeleteReceiver(builder); applyContentReceiver(builder); return new Notification(context, options, builder, triggerReceiver); }
public void showNotification(String msg) { Log.d("AlarmService", "Preparing to send notification...: " + msg); /** Setting Up Alarm* */ alarmNotificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity( getActivity(), 0, new Intent(getActivity(), AlertCallerFragmentActivity.class), 0); Uri sound = Uri.parse( "android.resource://" + getActivity().getPackageName() + "/" + R.raw.soundsmedication); /** Building Notifications* */ NotificationCompat.Builder alamNotificationBuilder = new NotificationCompat.Builder(getActivity()) .setContentTitle("Malaria Prevention") .setSmallIcon(R.drawable.appicon_themed) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentText(msg); alamNotificationBuilder.setSound(sound); alamNotificationBuilder.setContentIntent(contentIntent); alarmNotificationManager.notify(1, alamNotificationBuilder.build()); Log.d("AlarmService", "Notification sent."); }
private void Vibrate( Context ctx, AlertType alert, String bgValue, Boolean overrideSilent, int timeFromStartPlaying) { Log.d(TAG, "Vibrate called timeFromStartPlaying = " + timeFromStartPlaying); Log.d("ALARM", "setting vibrate alarm"); int profile = getAlertProfile(ctx); // We use timeFromStartPlaying as a way to force vibrating/ non vibrating... if (profile != ALERT_PROFILE_ASCENDING) { // We start from the non ascending part... timeFromStartPlaying = MAX_ASCENDING; } String title = bgValue + " " + alert.name; String content = "BG LEVEL ALERT: " + bgValue; Intent intent = new Intent(ctx, SnoozeActivity.class); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx) .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on) .setContentTitle(title) .setContentText(content) .setContentIntent(notificationIntent(ctx, intent)) .setDeleteIntent(snoozeIntent(ctx)); if (profile != ALERT_PROFILE_VIBRATE_ONLY && profile != ALERT_PROFILE_SILENT) { if (timeFromStartPlaying >= MAX_VIBRATING) { // Before this, we only vibrate... float volumeFrac = (float) (timeFromStartPlaying - MAX_VIBRATING) / (MAX_ASCENDING - MAX_VIBRATING); volumeFrac = Math.min(volumeFrac, 1); if (profile == ALERT_PROFILE_MEDIUM) { volumeFrac = (float) 0.7; } Log.d(TAG, "Vibrate volumeFrac = " + volumeFrac); boolean isRingTone = EditAlertActivity.isPathRingtone(ctx, alert.mp3_file); if (isRingTone && !overrideSilent) { builder.setSound(Uri.parse(alert.mp3_file)); } else { if (overrideSilent || isLoudPhone(ctx)) { PlayFile(ctx, alert.mp3_file, volumeFrac); } } } } if (profile != ALERT_PROFILE_SILENT && alert.vibrate) { builder.setVibrate(Notifications.vibratePattern); } NotificationManager mNotifyMgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); mNotifyMgr.cancel(Notifications.exportAlertNotificationId); mNotifyMgr.notify(Notifications.exportAlertNotificationId, builder.build()); }
private void setNotificationSound( Context context, Bundle extras, NotificationCompat.Builder mBuilder) { String soundname = getString(extras, SOUNDNAME); if (soundname == null) { soundname = getString(extras, SOUND); } if (soundname != null) { Uri sound = Uri.parse( ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/raw/" + soundname); Log.d(LOG_TAG, sound.toString()); mBuilder.setSound(sound); } else { mBuilder.setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI); } }
private void playNotificationAlarm(Context context, int textResId) { 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); notificationManager.notify(Constants.PUSH_NOTIFICATION_ALARM_ID, builder.build()); Toast.makeText(context, textResId, Toast.LENGTH_SHORT).show(); }
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 static void notify( String title, String text, String bigText, Boolean autoCancel, int id, String accountKey, long postId, Context context) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setTicker(text) .setSmallIcon(R.drawable.notification_default) .setAutoCancel(autoCancel) .setWhen(System.currentTimeMillis()) .setContentTitle(title) .setContentText(text) .setStyle(new NotificationCompat.BigTextStyle().bigText(bigText)); Uri ringtone = AppSettings.get().getRingtoneUri(); if (ringtone != null) { builder.setSound(ringtone); } Intent resultIntent = new Intent(context, HomeActivity.class); resultIntent.putExtra("account_key", accountKey); resultIntent.putExtra("post_id", postId); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(HomeActivity.class); stackBuilder.addNextIntent(resultIntent); int requestCode = (int) (Math.random() * Integer.MAX_VALUE); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(requestCode, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); Intent deleteIntent = new Intent(context, DeleteNotificationsReceiver.class); deleteIntent.putExtra("account_key", accountKey); deleteIntent.putExtra("post_id", postId); requestCode = (int) (Math.random() * Integer.MAX_VALUE); PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context, requestCode, deleteIntent, 0); builder.setDeleteIntent(deletePendingIntent); saveLastNotificationDisplayed(context, accountKey, postId); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(id, builder.build()); }
/** * Generate a notification * * @param pendingIntent pending intent * @param title title * @param message message * @return the notification */ private Notification buildNotification( PendingIntent pendingIntent, String title, String message) { NotificationCompat.Builder notif = new NotificationCompat.Builder(this); notif.setContentIntent(pendingIntent); notif.setSmallIcon(R.drawable.ri_notif_file_transfer_icon); notif.setWhen(System.currentTimeMillis()); notif.setAutoCancel(true); notif.setOnlyAlertOnce(true); notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); notif.setDefaults(Notification.DEFAULT_VIBRATE); notif.setContentTitle(title); notif.setContentText(message); return notif.build(); }
private void sendNotification(String text) { NotificationManager mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notification = new NotificationCompat.Builder(ctx); notification.setContentTitle(ctx.getString(R.string.app_name)); notification.setContentText(text); notification.setAutoCancel(true); if (Common.isVibrate()) { notification.setDefaults(Notification.DEFAULT_VIBRATE); } notification.setSmallIcon(R.drawable.ic_launcher); if (!TextUtils.isEmpty(Common.getRingtone())) { notification.setSound(Uri.parse(Common.getRingtone())); } mNotificationManager.notify(0, notification.build()); }
private void createNoifications(int icon, String endereco) { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); mBuilder = new NotificationCompat.Builder(TelaMaps.this) .setSmallIcon(icon) .setContentTitle("Dormi No Ponto") .setContentText(endereco); mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, mBuilder.build()); } catch (Exception e) { Log.e("ERROR", "" + e.getMessage()); } }
// creating notification function public void createNotification(Context context, String msg, String msgText, String msgAlert) { int id = (int) System.currentTimeMillis(); Intent i = new Intent(context, StopAlarm.class); i.putExtra("passuser", user); i.putExtra("inputCode", inputCode); i.putExtra( "reminderTitle", titleOfReminder); // store the title of the reminder which need to pass to the next activity i.putExtra("reminderStartTime", startTimeOfReminder); // store the start time of the reminder i.putExtra("remminderStartDate", startDateOfReminder); // store the start date of the reminder i.putExtra("repeat", repeatReminder); // store if user want this alarm to repeat the schedule. i.putExtra("selectedHour", selectedHour); i.putExtra("selectedMinute", selectedMinute); i.putExtra("selectedDay", selectedDay); i.putExtra("selectedMonth", selectedMonth); i.putExtra("selectedYear", selectedYear); i.putExtra("notirequestcode", notiRequestCode); notificIntent = PendingIntent.getActivity(context, id, i, 0); // using notification builder to set up the notification layout and configuration NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_alarm_24dp) .setContentTitle(msg) .setTicker(msgAlert) .setContentText(msgText); mBuilder.setContentIntent(notificIntent); mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE); Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound( uri); // this is to set the sound so that when notification is received, there will also // have default sound being released mBuilder.setAutoCancel(true); mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify( 1, mBuilder.build()); // to set to receive notification for each alarm change the int here. }
/** * Hace visibles las notificaciones * * @param mensajes Mensajes a notificar */ public void mostrarNotificacion(LinkedList<Mensaje> mensajes) { String textoNotificacionAuxiliar = ""; for (int i = 0; i < mensajes.size(); i++) { textoNotificacionAuxiliar += mensajes.get(i).getUsuario() + ": " + mensajes.get(i).getMensaje() + "\n"; } NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (mensajes.size() == 0) { mNotificationManager.cancel(mId); return; } if ((textoNotificacion.compareTo(textoNotificacionAuxiliar) == 0)) { return; } textoNotificacion = textoNotificacionAuxiliar; Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.not) .setContentTitle(getString(R.string.nuevos_mensajes)) .setStyle(new NotificationCompat.BigTextStyle().bigText(textoNotificacion)); // .setSound(alarmSound); mBuilder.setSound(alarmSound); Intent resultIntent = new Intent(this, ListaDeConversacionesActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(ListaDeConversacionesActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); // mId allows you to update the notification later on. mNotificationManager.notify(mId, mBuilder.build()); }
private void sendNotification(String msg, Context ctx) { mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); Intent myintent = new Intent(ctx, EventsDetailActivity.class); myintent.putExtra("message", msg); PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, myintent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle(ctx.getResources().getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentText(msg); mBuilder.setContentIntent(contentIntent); Uri nSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(nSound); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
private void addSessionInvitationNotification(Intent intent, ContactId contact) { /* Create pending intent */ Intent invitation = new Intent(intent); String title; if (mMultimediaMessagingSession) { invitation.setClass(this, MessagingSessionView.class); title = getString(R.string.title_recv_messaging_session); } else { invitation.setClass(this, StreamingSessionView.class); title = getString(R.string.title_recv_streaming_session); } invitation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); /* * If the PendingIntent has the same operation, action, data, categories, components, and * flags it will be replaced. Invitation should be notified individually so we use a random * generator to provide a unique request code and reuse it for the notification. */ int uniqueId = Utils.getUniqueIdForPendingIntent(); PendingIntent contentIntent = PendingIntent.getActivity(this, uniqueId, invitation, PendingIntent.FLAG_ONE_SHOT); String displayName = RcsContactUtil.getInstance(this).getDisplayName(contact); /* Create notification */ NotificationCompat.Builder notif = new NotificationCompat.Builder(this); notif.setContentIntent(contentIntent); notif.setSmallIcon(R.drawable.ri_notif_mm_session_icon); notif.setWhen(System.currentTimeMillis()); notif.setAutoCancel(true); notif.setOnlyAlertOnce(true); notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); notif.setDefaults(Notification.DEFAULT_VIBRATE); notif.setContentTitle(title); notif.setContentText(getString(R.string.label_from_args, displayName)); /* Send notification */ NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(uniqueId, notif.build()); }
private void newMessageNotification(String text, String senderEmail) { NotificationManager mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notification = new NotificationCompat.Builder(ctx); notification.setContentTitle(ctx.getString(R.string.app_name) + "-" + text); notification.setContentText(senderEmail); notification.setAutoCancel(true); if (Common.isVibrate()) { notification.setDefaults(Notification.DEFAULT_VIBRATE); } notification.setSmallIcon(R.drawable.ic_launcher); if (!TextUtils.isEmpty(Common.getRingtone())) { notification.setSound(Uri.parse(Common.getRingtone())); } Intent intent = new Intent(ctx, ChatActivity.class); intent.putExtra(Common.IS_NOTIF, true); intent.putExtra(Common.PROFILE_NAME, senderEmail); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(ctx, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); notification.setContentIntent(pi); mNotificationManager.notify(1, notification.build()); }
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); Uri sound = Uri.parse( Communications.ANDROID_RESOURCE + getApplicationContext().getPackageName() + Communications.FSLASH + R.raw.notification); mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("PingPal Messenger") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentText(msg); mBuilder.setContentIntent(contentIntent); // Check if sound is enabled SharedPreferences prefs = getApplicationContext().getSharedPreferences("pingpal", Activity.MODE_PRIVATE); boolean soundEnabled = prefs.getBoolean(Keys.Preferences.SOUND_ENABLED, true); if (soundEnabled) { mBuilder.setSound(sound); } mBuilder.setAutoCancel(true); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
private boolean updateNotification(final Context context) { Log.d(TAG, "updateNotification()"); lastUpdate = System.currentTimeMillis(); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); ArrayList<Timer> timers = new ArrayList<Timer>(); mNow = System.currentTimeMillis(); mNextTarget = 0; boolean alert = false; Log.d(TAG, "mNow: " + mNow); for (int j = 0; j < Timer.TIMER_IDS.length; j++) { Timer t = new Timer(context, j); timers.add(t); long tt = t.getTarget(); Log.d(TAG, "target(" + j + "): " + tt); if (tt > 0) { if (mNextTarget == 0 || tt < mNextTarget) { mNextTarget = tt; } if (tt < mNow) { alert = true; t.reset(context); } } } Log.d(TAG, "mNextTarget: " + mNextTarget); NotificationCompat.Builder b = new NotificationCompat.Builder(context); b.setPriority(1000); Intent i = new Intent(context, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); b.setContentIntent(PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); b.setContentTitle(context.getString(R.string.app_name)); b.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher)); b.setSmallIcon(R.drawable.ic_stat_timer); b.setAutoCancel(false); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { // GB- b.setContentText( context.getString( R.string.notification_text, timers.get(0).getFormatted(), timers.get(1).getFormatted(), timers.get(2).getFormatted())); } else { // HC+ RemoteViews v = new RemoteViews(context.getPackageName(), R.layout.notification); for (int j = 0; j < Timer.TIMER_IDS.length; j++) { v.setTextViewText(Timer.TIMER_IDS[j], timers.get(j).getFormatted().toString()); Intent ij = new Intent(Timer.TIMER_KEYS[j], null, context, UpdateReceiver.class); v.setOnClickPendingIntent( Timer.TIMER_IDS[j], PendingIntent.getBroadcast(context, 0, ij, PendingIntent.FLAG_UPDATE_CURRENT)); } v.setOnClickPendingIntent( R.id.settings, PendingIntent.getActivity( context, 0, new Intent(context, SettingsActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)); b.setContent(v); } if (mNextTarget <= 0 && !alert) { // we don't need any notification b.setOngoing(false); nm.notify(0, b.build()); return false; } else if (alert) { // show notification without running Timer b.setOngoing(mNextTarget > 0); SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); if (p.getBoolean("vibrate", true)) { b.setVibrate(VIBRATE); } String n = p.getString("notification", null); if (n == null) { // default b.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } else if (n.length() > 1) { try { b.setSound(Uri.parse(n)); } catch (Exception e) { Log.e(TAG, "invalid notification uri", e); b.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } // else: silent nm.notify(0, b.build()); return true; } else { // show notification with running Timer b.setOngoing(true); nm.notify(0, b.build()); return true; } }
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); }
public void createNotification(Context context, Bundle extras) { int notId = 0; try { notId = Integer.parseInt(extras.getString("notId")); } catch (NumberFormatException e) { Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage()); } catch (Exception e) { Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage()); } if (notId == 0) { // no notId passed, so assume we want to show all notifications, so make it a random number notId = new Random().nextInt(100000); Log.d(TAG, "Generated random notId: " + notId); } else { Log.d(TAG, "Received notId: " + notId); } NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); String appName = getAppName(context); Intent notificationIntent = new Intent(context, PushHandlerActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("pushBundle", extras); PendingIntent contentIntent = PendingIntent.getActivity( context, notId, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); int defaults = Notification.DEFAULT_ALL; if (extras.getString("defaults") != null) { try { defaults = Integer.parseInt(extras.getString("defaults")); } catch (NumberFormatException ignore) { } } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setDefaults(defaults) .setSmallIcon(getSmallIcon(context, extras)) .setWhen(System.currentTimeMillis()) .setContentTitle(extras.getString("title")) .setTicker(extras.getString("title")) .setContentIntent(contentIntent) .setColor(getColor(extras)) .setAutoCancel(true); String message = extras.getString("message"); if (message != null) { mBuilder.setContentText(message); } else { mBuilder.setContentText("<missing message content>"); } String msgcnt = extras.getString("msgcnt"); if (msgcnt != null) { mBuilder.setNumber(Integer.parseInt(msgcnt)); } String soundName = extras.getString("sound"); if (soundName != null) { Resources r = context.getResources(); int resourceId = r.getIdentifier(soundName, "raw", context.getPackageName()); Uri soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + resourceId); mBuilder.setSound(soundUri); defaults &= ~Notification.DEFAULT_SOUND; mBuilder.setDefaults(defaults); } final Notification notification = mBuilder.build(); final int largeIcon = getLargeIcon(context, extras); if (largeIcon > -1) { notification.contentView.setImageViewResource(android.R.id.icon, largeIcon); } mNotificationManager.notify(appName, notId, notification); }
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()); }
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()); } } }
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()); }
@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()); } }
@Override public Builder setSound(Uri sound, int streamType) { super.setSound(sound, streamType); return this; }
@Override public Builder setSound(Uri sound) { super.setSound(sound); return this; }