List of usage examples for android.app Notification DEFAULT_LIGHTS
int DEFAULT_LIGHTS
To view the source code for android.app Notification DEFAULT_LIGHTS.
Click Source Link
From source file:com.embeddedlog.LightUpDroid.timer.TimerReceiver.java
private void showTimesUpNotification(final Context context, TimerObj timerObj) { // Content Intent. When clicked will show the timer full screen PendingIntent contentIntent = PendingIntent.getActivity(context, timerObj.mTimerId, new Intent(context, TimerAlertFullScreen.class).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId),// w w w .jav a 2 s. c om PendingIntent.FLAG_UPDATE_CURRENT); // Add one minute action button PendingIntent addOneMinuteAction = PendingIntent.getBroadcast(context, timerObj.mTimerId, new Intent(Timers.NOTIF_TIMES_UP_PLUS_ONE).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId), PendingIntent.FLAG_UPDATE_CURRENT); // Add stop/done action button PendingIntent stopAction = PendingIntent.getBroadcast(context, timerObj.mTimerId, new Intent(Timers.NOTIF_TIMES_UP_STOP).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId), PendingIntent.FLAG_UPDATE_CURRENT); // Notification creation Notification notification = new Notification.Builder(context).setContentIntent(contentIntent) .addAction(R.drawable.ic_menu_add, context.getResources().getString(R.string.timer_plus_1_min), addOneMinuteAction) .addAction( timerObj.getDeleteAfterUse() ? android.R.drawable.ic_menu_close_clear_cancel : R.drawable.ic_stop_normal, timerObj.getDeleteAfterUse() ? context.getResources().getString(R.string.timer_done) : context.getResources().getString(R.string.timer_stop), stopAction) .setContentTitle(timerObj.getLabelOrDefault(context)) .setContentText(context.getResources().getString(R.string.timer_times_up)) .setSmallIcon(R.drawable.stat_notify_timer).setOngoing(true).setAutoCancel(false) .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS).setWhen(0).build(); // Send the notification using the timer's id to identify the // correct notification ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(timerObj.mTimerId, notification); if (Timers.LOGGING) { Log.v(TAG, "Setting times-up notification for " + timerObj.getLabelOrDefault(context) + " #" + timerObj.mTimerId); } }
From source file:se.oort.clockify.timer.TimerReceiver.java
private void showTimesUpNotification(final Context context, TimerObj timerObj) { // Content Intent. When clicked will show the timer full screen PendingIntent contentIntent = PendingIntent.getActivity(context, timerObj.mTimerId, new Intent(context, TimerAlertFullScreen.class).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId),/*from ww w.jav a 2s .c om*/ PendingIntent.FLAG_UPDATE_CURRENT); // Add one minute action button PendingIntent addOneMinuteAction = PendingIntent.getBroadcast(context, timerObj.mTimerId, new Intent(Timers.NOTIF_TIMES_UP_PLUS_ONE).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId), PendingIntent.FLAG_UPDATE_CURRENT); // Add stop/done action button PendingIntent stopAction = PendingIntent.getBroadcast(context, timerObj.mTimerId, new Intent(Timers.NOTIF_TIMES_UP_STOP).putExtra(Timers.TIMER_INTENT_EXTRA, timerObj.mTimerId), PendingIntent.FLAG_UPDATE_CURRENT); // Notification creation Notification notification = new Notification.Builder(context).setContentIntent(contentIntent) .addAction(R.drawable.ic_menu_add, context.getResources().getString(R.string.timer_plus_1_min), addOneMinuteAction) .addAction( timerObj.getDeleteAfterUse() ? android.R.drawable.ic_menu_close_clear_cancel : R.drawable.ic_stop_normal, timerObj.getDeleteAfterUse() ? context.getResources().getString(R.string.timer_done) : context.getResources().getString(R.string.timer_stop), stopAction) .setContentTitle(timerObj.getLabelOrDefault(context)) .setContentText(context.getResources().getString(R.string.timer_times_up)) .setSmallIcon(R.drawable.stat_notify_timer).setOngoing(true).setAutoCancel(false) .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS).setWhen(0).build(); // Send the notification using the timer's id to identify the // correct notification ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(timerObj.mTimerId, notification); if (Timers.LOGGING) { Log.v(LOG_TAG, "Setting times-up notification for " + timerObj.getLabelOrDefault(context) + " #" + timerObj.mTimerId); } }
From source file:com.android.mms.transaction.MessagingNotification.java
public static void blockingUpdateNewIccMessageIndicator(Context context, String address, String message, int subId, long timeMillis) { final Notification.Builder noti = new Notification.Builder(context).setWhen(timeMillis); Contact contact = Contact.get(address, false); NotificationInfo info = getNewIccMessageNotificationInfo(context, true /* isSms */, address, message, null /* subject */, subId, timeMillis, null /* attachmentBitmap */, contact, WorkingMessage.TEXT); noti.setSmallIcon(R.drawable.stat_notify_sms); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); // Update the notification. PendingIntent pendingIntent;/*from w ww. j a va 2s . co m*/ if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { pendingIntent = PendingIntent.getActivity(context, 0, info.mClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); } else { // Use requestCode to avoid updating all intents of previous notifications pendingIntent = PendingIntent.getActivity(context, ICC_NOTIFICATION_ID_BASE + subId, info.mClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); } String title = info.mTitle; noti.setContentTitle(title).setContentIntent(pendingIntent) //taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)) .setCategory(Notification.CATEGORY_MESSAGE).setPriority(Notification.PRIORITY_DEFAULT); int defaults = 0; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); boolean vibrate = false; if (sp.contains(MessagingPreferenceActivity.NOTIFICATION_VIBRATE)) { // The most recent change to the vibrate preference is to store a boolean // value in NOTIFICATION_VIBRATE. If prefs contain that preference, use that // first. vibrate = sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_VIBRATE, false); } else if (sp.contains(MessagingPreferenceActivity.NOTIFICATION_VIBRATE_WHEN)) { // This is to support the pre-JellyBean MR1.1 version of vibrate preferences // when vibrate was a tri-state setting. As soon as the user opens the Messaging // app's settings, it will migrate this setting from NOTIFICATION_VIBRATE_WHEN // to the boolean value stored in NOTIFICATION_VIBRATE. String vibrateWhen = sp.getString(MessagingPreferenceActivity.NOTIFICATION_VIBRATE_WHEN, null); vibrate = "always".equals(vibrateWhen); } if (vibrate) { defaults |= Notification.DEFAULT_VIBRATE; } String ringtoneStr = sp.getString(MessagingPreferenceActivity.NOTIFICATION_RINGTONE, null); noti.setSound(TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr)); Log.d(TAG, "blockingUpdateNewIccMessageIndicator: adding sound to the notification"); defaults |= Notification.DEFAULT_LIGHTS; noti.setDefaults(defaults); // set up delete intent noti.setDeleteIntent(PendingIntent.getBroadcast(context, 0, sNotificationOnDeleteIntent, 0)); final Notification notification; // This sets the text for the collapsed form: noti.setContentText(info.formatBigMessage(context)); if (info.mAttachmentBitmap != null) { // The message has a picture, show that notification = new Notification.BigPictureStyle(noti).bigPicture(info.mAttachmentBitmap) // This sets the text for the expanded picture form: .setSummaryText(info.formatPictureMessage(context)).build(); } else { // Show a single notification -- big style with the text of the whole message notification = new Notification.BigTextStyle(noti).bigText(info.formatBigMessage(context)).build(); } notifyUserIfFullScreen(context, title); nm.notify(ICC_NOTIFICATION_ID_BASE + subId, notification); }
From source file:org.gaeproxy.GAEProxyService.java
private void initSoundVibrateLights(Notification notification) { notification.sound = null; notification.defaults |= Notification.DEFAULT_LIGHTS; }
From source file:nl.vanvianen.android.gcm.GCMIntentService.java
@Override @SuppressWarnings("unchecked") protected void onMessage(Context context, Intent intent) { Log.d(LCAT, "Push notification received"); boolean isTopic = false; HashMap<String, Object> data = new HashMap<String, Object>(); for (String key : intent.getExtras().keySet()) { Object value = intent.getExtras().get(key); Log.d(LCAT, "Message key: \"" + key + "\" value: \"" + value + "\""); if (key.equals("from") && value instanceof String && ((String) value).startsWith("/topics/")) { isTopic = true;/* ww w. j a v a 2 s . c om*/ } String eventKey = key.startsWith("data.") ? key.substring(5) : key; data.put(eventKey, intent.getExtras().get(key)); if (value instanceof String && ((String) value).startsWith("{")) { Log.d(LCAT, "Parsing JSON string..."); try { JSONObject json = new JSONObject((String) value); Iterator<String> keys = json.keys(); while (keys.hasNext()) { String jKey = keys.next(); String jValue = json.getString(jKey); Log.d(LCAT, "JSON key: \"" + jKey + "\" value: \"" + jValue + "\""); data.put(jKey, jValue); } } catch (JSONException ex) { Log.d(LCAT, "JSON error: " + ex.getMessage()); } } } /* Store data to be retrieved when resuming app as a JSON object, serialized as a String, otherwise * Ti.App.Properties.getString(GCMModule.LAST_DATA) doesn't work. */ JSONObject json = new JSONObject(data); TiApplication.getInstance().getAppProperties().setString(GCMModule.LAST_DATA, json.toString()); /* Get settings from notification object */ int smallIcon = 0; int largeIcon = 0; String sound = null; boolean vibrate = false; boolean insistent = false; String group = null; boolean localOnly = true; int priority = 0; boolean bigText = false; int notificationId = 1; Integer ledOn = null; Integer ledOff = null; String titleKey = DEFAULT_TITLE_KEY; String messageKey = DEFAULT_MESSAGE_KEY; String tickerKey = DEFAULT_TICKER_KEY; String title = null; String message = null; String ticker = null; boolean backgroundOnly = false; Map<String, Object> notificationSettings = new Gson().fromJson( TiApplication.getInstance().getAppProperties().getString(GCMModule.NOTIFICATION_SETTINGS, null), Map.class); if (notificationSettings != null) { if (notificationSettings.get("smallIcon") instanceof String) { smallIcon = getResource("drawable", (String) notificationSettings.get("smallIcon")); } else { Log.e(LCAT, "Invalid setting smallIcon, should be String"); } if (notificationSettings.get("largeIcon") instanceof String) { largeIcon = getResource("drawable", (String) notificationSettings.get("largeIcon")); } else { Log.e(LCAT, "Invalid setting largeIcon, should be String"); } if (notificationSettings.get("sound") != null) { if (notificationSettings.get("sound") instanceof String) { sound = (String) notificationSettings.get("sound"); } else { Log.e(LCAT, "Invalid setting sound, should be String"); } } if (notificationSettings.get("vibrate") != null) { if (notificationSettings.get("vibrate") instanceof Boolean) { vibrate = (Boolean) notificationSettings.get("vibrate"); } else { Log.e(LCAT, "Invalid setting vibrate, should be Boolean"); } } if (notificationSettings.get("insistent") != null) { if (notificationSettings.get("insistent") instanceof Boolean) { insistent = (Boolean) notificationSettings.get("insistent"); } else { Log.e(LCAT, "Invalid setting insistent, should be Boolean"); } } if (notificationSettings.get("group") != null) { if (notificationSettings.get("group") instanceof String) { group = (String) notificationSettings.get("group"); } else { Log.e(LCAT, "Invalid setting group, should be String"); } } if (notificationSettings.get("localOnly") != null) { if (notificationSettings.get("localOnly") instanceof Boolean) { localOnly = (Boolean) notificationSettings.get("localOnly"); } else { Log.e(LCAT, "Invalid setting localOnly, should be Boolean"); } } if (notificationSettings.get("priority") != null) { if (notificationSettings.get("priority") instanceof Integer) { priority = (Integer) notificationSettings.get("priority"); } else if (notificationSettings.get("priority") instanceof Double) { priority = ((Double) notificationSettings.get("priority")).intValue(); } else { Log.e(LCAT, "Invalid setting priority, should be an integer, between PRIORITY_MIN (" + NotificationCompat.PRIORITY_MIN + ") and PRIORITY_MAX (" + NotificationCompat.PRIORITY_MAX + ")"); } } if (notificationSettings.get("bigText") != null) { if (notificationSettings.get("bigText") instanceof Boolean) { bigText = (Boolean) notificationSettings.get("bigText"); } else { Log.e(LCAT, "Invalid setting bigText, should be Boolean"); } } if (notificationSettings.get("titleKey") != null) { if (notificationSettings.get("titleKey") instanceof String) { titleKey = (String) notificationSettings.get("titleKey"); } else { Log.e(LCAT, "Invalid setting titleKey, should be String"); } } if (notificationSettings.get("messageKey") != null) { if (notificationSettings.get("messageKey") instanceof String) { messageKey = (String) notificationSettings.get("messageKey"); } else { Log.e(LCAT, "Invalid setting messageKey, should be String"); } } if (notificationSettings.get("tickerKey") != null) { if (notificationSettings.get("tickerKey") instanceof String) { tickerKey = (String) notificationSettings.get("tickerKey"); } else { Log.e(LCAT, "Invalid setting tickerKey, should be String"); } } if (notificationSettings.get("title") != null) { if (notificationSettings.get("title") instanceof String) { title = (String) notificationSettings.get("title"); } else { Log.e(LCAT, "Invalid setting title, should be String"); } } if (notificationSettings.get("message") != null) { if (notificationSettings.get("message") instanceof String) { message = (String) notificationSettings.get("message"); } else { Log.e(LCAT, "Invalid setting message, should be String"); } } if (notificationSettings.get("ticker") != null) { if (notificationSettings.get("ticker") instanceof String) { ticker = (String) notificationSettings.get("ticker"); } else { Log.e(LCAT, "Invalid setting ticker, should be String"); } } if (notificationSettings.get("ledOn") != null) { if (notificationSettings.get("ledOn") instanceof Integer) { ledOn = (Integer) notificationSettings.get("ledOn"); if (ledOn < 0) { Log.e(LCAT, "Invalid setting ledOn, should be positive"); ledOn = null; } } else { Log.e(LCAT, "Invalid setting ledOn, should be Integer"); } } if (notificationSettings.get("ledOff") != null) { if (notificationSettings.get("ledOff") instanceof Integer) { ledOff = (Integer) notificationSettings.get("ledOff"); if (ledOff < 0) { Log.e(LCAT, "Invalid setting ledOff, should be positive"); ledOff = null; } } else { Log.e(LCAT, "Invalid setting ledOff, should be Integer"); } } if (notificationSettings.get("backgroundOnly") != null) { if (notificationSettings.get("backgroundOnly") instanceof Boolean) { backgroundOnly = (Boolean) notificationSettings.get("backgroundOnly"); } else { Log.e(LCAT, "Invalid setting backgroundOnly, should be Boolean"); } } if (notificationSettings.get("notificationId") != null) { if (notificationSettings.get("notificationId") instanceof Integer) { notificationId = (Integer) notificationSettings.get("notificationId"); } else { Log.e(LCAT, "Invalid setting notificationId, should be Integer"); } } } else { Log.d(LCAT, "No notification settings found"); } /* If icon not found, default to appicon */ if (smallIcon == 0) { smallIcon = getResource("drawable", "appicon"); } /* If large icon not found, default to icon */ if (largeIcon == 0) { largeIcon = smallIcon; } /* Create intent to (re)start the app's root activity */ String pkg = TiApplication.getInstance().getApplicationContext().getPackageName(); Intent launcherIntent = TiApplication.getInstance().getApplicationContext().getPackageManager() .getLaunchIntentForPackage(pkg); launcherIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER); /* Grab notification content from data according to provided keys if not already set */ if (title == null && titleKey != null) { title = (String) data.get(titleKey); } if (message == null && messageKey != null) { message = (String) data.get(messageKey); } if (ticker == null && tickerKey != null) { ticker = (String) data.get(tickerKey); } Log.i(LCAT, "Title: " + title); Log.i(LCAT, "Message: " + message); Log.i(LCAT, "Ticker: " + ticker); /* Check for app state */ if (GCMModule.getInstance() != null) { /* Send data to app */ if (isTopic) { GCMModule.getInstance().sendTopicMessage(data); } else { GCMModule.getInstance().sendMessage(data); } /* Do not create notification if backgroundOnly and app is in foreground */ if (backgroundOnly && GCMModule.getInstance().isInForeground()) { Log.d(LCAT, "Notification received in foreground, no need for notification."); return; } } if (message == null) { Log.d(LCAT, "Message received but no 'message' specified in push notification payload, so will make this silent"); } else { Log.d(LCAT, "Creating notification..."); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), largeIcon); if (bitmap == null) { Log.d(LCAT, "No large icon found"); } NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setTicker(ticker) .setContentIntent( PendingIntent.getActivity(this, 0, launcherIntent, PendingIntent.FLAG_ONE_SHOT)) .setSmallIcon(smallIcon).setLargeIcon(bitmap); /* Name of group to group similar notifications together, can also be set in the push notification payload */ if (data.get("group") != null) { group = (String) data.get("group"); } if (group != null) { builder.setGroup(group); } Log.i(LCAT, "Group: " + group); /* Whether notification should be for this device only or bridged to other devices, can also be set in the push notification payload */ if (data.get("localOnly") != null) { localOnly = Boolean.valueOf((String) data.get("localOnly")); } builder.setLocalOnly(localOnly); Log.i(LCAT, "LocalOnly: " + localOnly); /* Specify notification priority, can also be set in the push notification payload */ if (data.get("priority") != null) { priority = Integer.parseInt((String) data.get("priority")); } if (priority >= NotificationCompat.PRIORITY_MIN && priority <= NotificationCompat.PRIORITY_MAX) { builder.setPriority(priority); Log.i(LCAT, "Priority: " + priority); } else { Log.e(LCAT, "Ignored invalid priority " + priority); } /* Specify whether bigtext should be used, can also be set in the push notification payload */ if (data.get("bigText") != null) { bigText = Boolean.valueOf((String) data.get("bigText")); } if (bigText) { builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); } Log.i(LCAT, "bigText: " + bigText); Notification notification = builder.build(); /* Sound, can also be set in the push notification payload */ if (data.get("sound") != null) { Log.d(LCAT, "Sound specified in notification"); sound = (String) data.get("sound"); } if ("default".equals(sound)) { Log.i(LCAT, "Sound: default sound"); notification.defaults |= Notification.DEFAULT_SOUND; } else if (sound != null) { Log.i(LCAT, "Sound " + sound); notification.sound = Uri.parse("android.resource://" + pkg + "/" + getResource("raw", sound)); } /* Vibrate, can also be set in the push notification payload */ if (data.get("vibrate") != null) { vibrate = Boolean.valueOf((String) data.get("vibrate")); } if (vibrate) { notification.defaults |= Notification.DEFAULT_VIBRATE; } Log.i(LCAT, "Vibrate: " + vibrate); /* Insistent, can also be set in the push notification payload */ if ("true".equals(data.get("insistent"))) { insistent = true; } if (insistent) { notification.flags |= Notification.FLAG_INSISTENT; } Log.i(LCAT, "Insistent: " + insistent); /* notificationId, set in push payload to specify multiple notifications should be shown. If not specified, subsequent notifications "override / overwrite" the older ones */ if (data.get("notificationId") != null) { if (data.get("notificationId") instanceof Integer) { notificationId = (Integer) data.get("notificationId"); } else if (data.get("notificationId") instanceof String) { try { notificationId = Integer.parseInt((String) data.get("notificationId")); } catch (NumberFormatException ex) { Log.e(LCAT, "Invalid setting notificationId, should be Integer"); } } else { Log.e(LCAT, "Invalid setting notificationId, should be Integer"); } } Log.i(LCAT, "Notification ID: " + notificationId); /* Specify LED flashing */ if (ledOn != null || ledOff != null) { notification.flags |= Notification.FLAG_SHOW_LIGHTS; if (ledOn != null) { notification.ledOnMS = ledOn; } if (ledOff != null) { notification.ledOffMS = ledOff; } } else { notification.defaults |= Notification.DEFAULT_LIGHTS; } notification.flags |= Notification.FLAG_AUTO_CANCEL; ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(notificationId, notification); } }
From source file:com.tct.email.NotificationController.java
/** Sets up the notification's sound and vibration based upon account details. */ private void setupSoundAndVibration(NotificationCompat.Builder builder, Account account) { String ringtoneUri = Settings.System.DEFAULT_NOTIFICATION_URI.toString(); boolean vibrate = false; // Use the Inbox notification preferences final Cursor accountCursor = mContext.getContentResolver().query( EmailProvider.uiUri("uiaccount", account.mId), UIProvider.ACCOUNTS_PROJECTION, null, null, null); com.tct.mail.providers.Account uiAccount = null; try {/* w w w.j a va 2 s .c o m*/ if (accountCursor.moveToFirst()) { uiAccount = com.tct.mail.providers.Account.builder().buildFrom(accountCursor); } } finally { accountCursor.close(); } if (uiAccount != null) { final Cursor folderCursor = mContext.getContentResolver().query(uiAccount.settings.defaultInbox, UIProvider.FOLDERS_PROJECTION, null, null, null); if (folderCursor == null) { // This can happen when the notification is for the security policy notification // that happens before the account is setup LogUtils.w(LOG_TAG, "Null folder cursor for mailbox %s", uiAccount.settings.defaultInbox); } else { Folder folder = null; try { if (folderCursor.moveToFirst()) { folder = new Folder(folderCursor); } } finally { folderCursor.close(); } if (folder != null) { final FolderPreferences folderPreferences = new FolderPreferences(mContext, uiAccount.getEmailAddress(), folder, true /* inbox */); ringtoneUri = folderPreferences.getNotificationRingtoneUri(); vibrate = folderPreferences.isNotificationVibrateEnabled(); } else { LogUtils.e(LOG_TAG, "Null folder for mailbox %s", uiAccount.settings.defaultInbox); } } } else { LogUtils.e(LOG_TAG, "Null uiAccount for account id %d", account.mId); } int defaults = Notification.DEFAULT_LIGHTS; if (vibrate) { defaults |= Notification.DEFAULT_VIBRATE; } builder.setSound(TextUtils.isEmpty(ringtoneUri) ? null : Uri.parse(ringtoneUri)).setDefaults(defaults); }
From source file:com.mattprecious.notisync.service.SecondaryService.java
private void handleCustomMessage(CustomMessage message) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); if (message.packageName.equals("com.whatsapp")) { builder.setSmallIcon(R.drawable.package_com_whatsapp); } else if (message.appName.contains("Gmail")) { builder.setSmallIcon(R.drawable.package_com_google_android_gm); } else {/* www .ja va2 s . c o m*/ builder.setSmallIcon(R.drawable.ic_stat_logo); } builder.setContentTitle(message.messageTitle); builder.setContentText(message.message); builder.setAutoCancel(true); SecondaryProfile profile = null; if (message.tag != null) { dbAdapter.openReadable(); profile = dbAdapter.getSecondaryProfileByTag(message.tag); dbAdapter.close(); if (profile != null) { if (!profile.isEnabled()) { return; } if (profile.isUnconnectedOnly()) { if (isNetworkAvailable()) { return; } } int defaults = 0; if (profile.isVibrate()) { defaults |= Notification.DEFAULT_VIBRATE; } if (profile.isLed()) { defaults |= Notification.DEFAULT_LIGHTS; } //builder.setContentTitle(profile.getName()); builder.setDefaults(defaults); builder.setSound(getRingtoneUri(profile.getRingtone())); openNotificationDatabaseWrite(); notificationsDbAdapter.insertNotification(message.packageName, message.tag, message.appName, message.messageTitle, message.message, message.time); notificationsDbAdapter.close(); } } if (profile == null) { builder.setDefaults(Notification.DEFAULT_ALL); } Intent showIntent = new Intent(this, NotificationListActivity.class); PendingIntent intent = PendingIntent.getActivity(this, 0, showIntent, 0); builder.setContentIntent(intent); Notification notification = new NotificationCompat.BigTextStyle(builder) //.bigText(message.messageTitle) .bigText(message.message).build(); // use the profile ID to determine the notification ID // TODO: note that if somehow a profile ID is ~2^32, we're overwriting // notifications... int notificationId = NOTIFICATION_ID_CUSTOM; if (profile != null) { notificationId += profile.getId(); } notificationManager.notify(notificationId, notification); }
From source file:com.pacoapp.paco.triggering.NotificationCreator.java
private Notification createAndroidNotification(Context context, NotificationHolder notificationHolder, String experimentTitle, String message, String experimentSpecificRingtone, Integer color, Boolean dismissible) {//from w w w . j ava2 s .c o m int icon = R.drawable.paco32; String tickerText = context.getString(R.string.time_for_notification_title) + experimentTitle; if (notificationHolder.isCustomNotification()) { tickerText = message; } Intent surveyIntent = new Intent(context, ExperimentExecutor.class); surveyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); surveyIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue()); PendingIntent notificationIntent = PendingIntent.getActivity(context, notificationHolder.getId().intValue(), surveyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Adding bigText style to notification enabling larger messages to be read // in the notification pane NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle(); bigStyle.setBigContentTitle(experimentTitle); bigStyle.bigText(message); // Make sure we have a color, or use the default if (color == null) { color = PacoNotificationAction.DEFAULT_COLOR; } //Make sure we know whether the notification is dismissible/not, or use default if (dismissible == null) { dismissible = PacoNotificationAction.DEFAULT_DISMISSIBLE; } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context).setSmallIcon(icon) .setContentTitle(experimentTitle).setTicker(tickerText).setContentText(message) .setWhen(notificationHolder.getAlarmTime()).setContentIntent(notificationIntent) .setOngoing(!dismissible) //whether it's dismissible .setAutoCancel(dismissible) //whether it should disappear on user click .setLights(color, PacoNotificationAction.DEFAULT_NOTIFICATION_DELAY, PacoNotificationAction.DEFAULT_NOTIFICATION_DELAY) .setStyle(bigStyle); int defaults = Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS; defaults = getRingtone(context, notificationBuilder, defaults, experimentSpecificRingtone); notificationBuilder.setDefaults(defaults); return notificationBuilder.build(); }
From source file:com.battlelancer.seriesguide.service.NotificationService.java
private void onNotify(final Cursor upcomingEpisodes, List<Integer> notifyPositions, long latestAirtime) { final Context context = getApplicationContext(); CharSequence tickerText;/*from w w w. java 2 s .co m*/ CharSequence contentTitle; CharSequence contentText; PendingIntent contentIntent; // base intent for task stack final Intent showsIntent = new Intent(context, ShowsActivity.class); showsIntent.putExtra(ShowsActivity.InitBundle.SELECTED_TAB, ShowsActivity.InitBundle.INDEX_TAB_UPCOMING); final int count = notifyPositions.size(); if (count == 1) { // notify in detail about one episode Timber.d("Notifying about 1 new episode"); upcomingEpisodes.moveToPosition(notifyPositions.get(0)); final String showTitle = upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE); tickerText = getString(R.string.upcoming_show, showTitle); contentTitle = showTitle + " " + Utils.getEpisodeNumber(this, upcomingEpisodes.getInt(NotificationQuery.SEASON), upcomingEpisodes.getInt(NotificationQuery.NUMBER)); // "8:00 PM on Network" final String releaseTime = TimeTools.formatToLocalReleaseTime(this, TimeTools.getEpisodeReleaseTime( this, upcomingEpisodes.getLong(NotificationQuery.EPISODE_FIRST_RELEASE_MS))); final String network = upcomingEpisodes.getString(NotificationQuery.NETWORK); contentText = getString(R.string.upcoming_show_detailed, releaseTime, network); Intent episodeDetailsIntent = new Intent(context, EpisodesActivity.class); episodeDetailsIntent.putExtra(EpisodesActivity.InitBundle.EPISODE_TVDBID, upcomingEpisodes.getInt(NotificationQuery._ID)); episodeDetailsIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime); contentIntent = TaskStackBuilder.create(context).addNextIntent(showsIntent) .addNextIntent(episodeDetailsIntent) .getPendingIntent(REQUEST_CODE_SINGLE_EPISODE, PendingIntent.FLAG_CANCEL_CURRENT); } else { // notify about multiple episodes Timber.d("Notifying about " + count + " new episodes"); tickerText = getString(R.string.upcoming_episodes); contentTitle = getString(R.string.upcoming_episodes_number, count); contentText = getString(R.string.upcoming_display); contentIntent = TaskStackBuilder.create(context) .addNextIntent(showsIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime)) .getPendingIntent(REQUEST_CODE_MULTIPLE_EPISODES, PendingIntent.FLAG_CANCEL_CURRENT); } final NotificationCompat.Builder nb = new NotificationCompat.Builder(context); if (AndroidUtils.isJellyBeanOrHigher()) { Timber.d("Building rich notification (JB+)"); // JELLY BEAN and above if (count == 1) { // single episode upcomingEpisodes.moveToPosition(notifyPositions.get(0)); maybeSetPoster(context, nb, upcomingEpisodes.getString(NotificationQuery.POSTER)); final String episodeTitle = upcomingEpisodes.getString(NotificationQuery.TITLE); final String episodeSummary = upcomingEpisodes.getString(NotificationQuery.OVERVIEW); final SpannableStringBuilder bigText = new SpannableStringBuilder(); bigText.append(TextUtils.isEmpty(episodeTitle) ? "" : episodeTitle); bigText.setSpan(new StyleSpan(Typeface.BOLD), 0, bigText.length(), 0); bigText.append("\n"); bigText.append(TextUtils.isEmpty(episodeSummary) ? "" : 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)); checkInActionIntent .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); PendingIntent checkInIntent = PendingIntent.getActivity(context, REQUEST_CODE_ACTION_CHECKIN, checkInActionIntent, PendingIntent.FLAG_CANCEL_CURRENT); 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 for (int displayIndex = 0; displayIndex < Math.min(count, 5); displayIndex++) { if (!upcomingEpisodes.moveToPosition(notifyPositions.get(displayIndex))) { // could not go to the desired position (testing just in case) break; } final SpannableStringBuilder lineText = new SpannableStringBuilder(); // show title String showTitle = upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE); lineText.append(TextUtils.isEmpty(showTitle) ? "" : showTitle); lineText.setSpan(new StyleSpan(Typeface.BOLD), 0, lineText.length(), 0); lineText.append(" "); // "8:00 PM on Network" String releaseTime = TimeTools.formatToLocalReleaseTime(this, TimeTools.getEpisodeReleaseTime( this, upcomingEpisodes.getLong(NotificationQuery.EPISODE_FIRST_RELEASE_MS))); String network = upcomingEpisodes.getString(NotificationQuery.NETWORK); lineText.append(getString(R.string.upcoming_show_detailed, releaseTime, 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.moveToPosition(notifyPositions.get(0)); maybeSetPoster(context, nb, upcomingEpisodes.getString(NotificationQuery.POSTER)); } } // notification sound final String ringtoneUri = NotificationSettings.getNotificationsRingtone(context); // If the string is empty, the user chose silent... if (ringtoneUri.length() != 0) { // ...otherwise set the specified ringtone Timber.d("Notification has sound"); nb.setSound(Uri.parse(ringtoneUri)); } // vibration if (NotificationSettings.isNotificationVibrating(context)) { Timber.d("Notification vibrates"); 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.setColor(getResources().getColor(R.color.accent_primary)); nb.setPriority(NotificationCompat.PRIORITY_DEFAULT); nb.setCategory(NotificationCompat.CATEGORY_EVENT); Timber.d("Setting delete intent with episode time: " + latestAirtime); Intent i = new Intent(this, NotificationService.class); i.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime); PendingIntent deleteIntent = PendingIntent.getService(this, REQUEST_CODE_DELETE_INTENT, i, PendingIntent.FLAG_CANCEL_CURRENT); 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); }
From source file:com.nbplus.push.PushService.java
/** * Configures service as a foreground service. A foreground service is a service that's doing * something the user is actively aware of (such as playing music), and must appear to the * user as a notification. That's why we create the notification here. *//*from w ww . j ava2 s . c om*/ void setUpAsForeground() { // notification's layout mBuilder = new NotificationCompat.Builder(this); CharSequence ticker = getString(R.string.push_noti_body); int apiVersion = Build.VERSION.SDK_INT; mBuilder.setSmallIcon(R.drawable.ic_notification_push).setAutoCancel(false).setOngoing(true) .setContentTitle(getString(R.string.push_name)).setContentText(ticker) .setPriority(NotificationCompat.PRIORITY_MAX).setTicker(ticker); mNotification = mBuilder.build(); mNotification.flags |= Notification.FLAG_ONGOING_EVENT; mNotification.defaults |= Notification.DEFAULT_LIGHTS; startForeground(NOTIFICATION_ID, mNotification); }