List of usage examples for android.app Notification DEFAULT_VIBRATE
int DEFAULT_VIBRATE
To view the source code for android.app Notification DEFAULT_VIBRATE.
Click Source Link
From source file:indrora.atomic.irc.IRCService.java
/** * Update notification and vibrate and/or flash a LED light if needed * * @param text The ticker text to display * @param contentText The text to display in the notification dropdown * If null, this makes the notification update to be the connection status. * @param vibrate True if the device should vibrate, false otherwise * @param sound True if the device should make sound, false otherwise * @param light True if the device should flash a LED light, false otherwise *///from www.j av a2 s . c om private void updateNotification(String text, String contentText, boolean vibrate, boolean sound, boolean light) { if (foreground) { // I give up. Android changed how this works -- Hope it never goes away. notification = new Notification(R.drawable.ic_service_icon, text, System.currentTimeMillis()); Intent notifyIntent = new Intent(this, ServersActivity.class); //notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //conetntText is null when you have nothing to display; by default, if you supply any, it will //use whatever is handed as the body of the notification. // If you hand it null, you are given a status line that describes what is going on. if (contentText == null) { if (newMentions >= 1) { StringBuilder sb = new StringBuilder(); for (Conversation conv : mentions.values()) { sb.append(conv.getName() + " (" + conv.getNewMentions() + "), "); } contentText = getString(R.string.notification_mentions, sb.substring(0, sb.length() - 2)); // We're going to work through the mentions keys. The first half is // the server ID, the other half // is the channel that the mention belongs to. int ServerID = -1; String Convo = ""; for (String convID : mentions.keySet()) { ServerID = Integer.parseInt(convID.substring(0, convID.indexOf(':'))); Convo = convID.substring(convID.indexOf(':') + 1); } Log.d("IRCService", "Jump target is '" + Convo + "'"); notifyIntent.setClass(this, ConversationActivity.class); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); notifyIntent.putExtra("serverId", ServerID); notifyIntent.putExtra(ConversationActivity.EXTRA_TARGET, "" + Convo); } else { if (!connectedServerTitles.isEmpty()) { StringBuilder sb = new StringBuilder(); for (String title : connectedServerTitles) { sb.append(title + ", "); } contentText = getString(R.string.notification_connected, sb.substring(0, sb.length() - 2)); } else { contentText = getString(R.string.notification_not_connected); } } } PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, getText(R.string.app_name), contentText, contentIntent); // We only want to vibrate if it's been $ARBITRARY_AMOUNT_OF_TIME // since we last buzzed. vibrate = vibrate && (System.currentTimeMillis() - lastVibrationTime > 2000); if (vibrate) { notification.defaults |= Notification.DEFAULT_VIBRATE; lastVibrationTime = System.currentTimeMillis(); } if (sound) { // buzz the user with an audible sound. notification.sound = settings.getHighlightSoundLocation(); } if (light) { notification.ledARGB = NOTIFICATION_LED_COLOR; notification.ledOnMS = NOTIFICATION_LED_ON_MS; notification.ledOffMS = NOTIFICATION_LED_OFF_MS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; } notification.number = newMentions; notificationManager.notify(FOREGROUND_NOTIFICATION, notification); } }
From source file:com.google.appinventor.components.runtime.ProbeBase.java
@SimpleFunction(description = "Create a notication with message to wake up " + "another activity when tap on the notification") public void CreateNotification(String title, String text, boolean enabledSound, boolean enabledVibrate, String packageName, String className, String extraKey, String extraVal) throws ClassNotFoundException { Intent activityToLaunch = new Intent(Intent.ACTION_MAIN); Log.i(TAG, "packageName: " + packageName); Log.i(TAG, "className: " + className); // for local AI instance, all classes are under the package // "appinventor.ai_test" // but for those runs on Google AppSpot(AppEngine), the package name will be // "appinventor.ai_GoogleAccountUserName" // e.g. pakageName = appinventor.ai_HomerSimpson.HelloPurr // && className = appinventor.ai_HomerSimpson.HelloPurr.Screen1 ComponentName component = new ComponentName(packageName, className); activityToLaunch.setComponent(component); activityToLaunch.putExtra(extraKey, extraVal); Log.i(TAG, "we found the class for intent to send into notificaiton"); activityToLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); mContentIntent = PendingIntent.getActivity(mainUIThreadActivity, 0, activityToLaunch, 0); Long currentTimeMillis = System.currentTimeMillis(); notification = new Notification(R.drawable.stat_notify_chat, "Activate Notification!", currentTimeMillis); Log.i(TAG, "After creating notification"); notification.contentIntent = mContentIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; // reset the notification notification.defaults = 0;/* ww w . ja v a2 s . c o m*/ if (enabledSound) notification.defaults |= Notification.DEFAULT_SOUND; if (enabledVibrate) notification.defaults |= Notification.DEFAULT_VIBRATE; notification.setLatestEventInfo(mainUIThreadActivity, (CharSequence) title, (CharSequence) text, mContentIntent); Log.i(TAG, "after updated notification contents"); mNM.notify(PROBE_NOTIFICATION_ID, notification); Log.i(TAG, "notified"); }
From source file:com.mattprecious.notisync.service.SecondaryService.java
private void handleGtalkMessage(GtalkMessage message) { if (!Preferences.getSecondaryGtalkEnabled(this)) { return;/*from www . ja v a2 s.com*/ } if (Preferences.getSecondaryGtalkUnconnectedOnly(this)) { if (isNetworkAvailable()) { return; } } if (gtalkMessages.containsKey(message.sender)) { List<GtalkMessage> messages = gtalkMessages.remove(message.sender); messages.add(message); gtalkMessages.put(message.sender, messages); } else { List<GtalkMessage> list = Lists.newArrayList(); list.add(message); gtalkMessages.put(message.sender, list); } NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.package_talk); builder.setSound(getRingtoneUri(Preferences.getSecondaryGtalkRingtone(this))); builder.setAutoCancel(true); int defaults = 0; if (Preferences.getSecondaryGtalkVibrate(this)) { defaults |= Notification.DEFAULT_VIBRATE; } if (Preferences.getSecondaryGtalkLights(this)) { defaults |= Notification.DEFAULT_LIGHTS; } builder.setDefaults(defaults); PendingIntent deleteIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_GTALK_NOTIFICATION_DELETED), 0); builder.setContentIntent(deleteIntent); builder.setDeleteIntent(deleteIntent); List<List<NotificationData>> threadList = Lists.newArrayList(); List<Entry<String, List<GtalkMessage>>> entryList = Lists .reverse(Lists.newArrayList(gtalkMessages.entrySet())); for (Entry<String, List<GtalkMessage>> entry : entryList) { List<NotificationData> data = Lists.newArrayList(); for (GtalkMessage msg : entry.getValue()) { data.add(new NotificationData(msg.sender, msg.message)); } threadList.add(data); } notificationManager.notify(NOTIFICATION_ID_GTALK, buildRichNotification(builder, threadList, null)); openNotificationDatabaseWrite(); notificationsDbAdapter.insertNotification("com.google.android.talk", "talk", "Hangouts", message.sender, message.message, System.currentTimeMillis() + ""); notificationsDbAdapter.close(); }
From source file:com.nbplus.vbroadlauncher.BroadcastPushReceiver.java
private void showNotification(Context context, int notificationId, 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);// www .j av a2 s . co m builder.setSmallIcon(R.drawable.ic_notification_noti); 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) { PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); } notificationManager.notify(notificationId, builder.build()); }
From source file:org.mariotaku.twidere.util.AsyncTwitterWrapper.java
private Notification buildNotification(final String title, final String message, final int icon, final Intent content_intent, final Intent delete_intent) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); builder.setTicker(message);/* www . j a va2 s .c o m*/ builder.setContentTitle(title); builder.setContentText(message); builder.setAutoCancel(true); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(icon); if (delete_intent != null) { builder.setDeleteIntent( PendingIntent.getBroadcast(mContext, 0, delete_intent, PendingIntent.FLAG_UPDATE_CURRENT)); } if (content_intent != null) { builder.setContentIntent( PendingIntent.getActivity(mContext, 0, content_intent, PendingIntent.FLAG_UPDATE_CURRENT)); } int defaults = 0; if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_SOUND, false)) { builder.setSound(Uri.parse(mPreferences.getString(PREFERENCE_KEY_NOTIFICATION_RINGTONE, Settings.System.DEFAULT_RINGTONE_URI.getPath())), Notification.STREAM_DEFAULT); } if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_VIBRATION, false)) { defaults |= Notification.DEFAULT_VIBRATE; } if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_HAVE_LIGHTS, false)) { final int color_def = mResources.getColor(R.color.holo_blue_dark); final int color = mPreferences.getInt(PREFERENCE_KEY_NOTIFICATION_LIGHT_COLOR, color_def); builder.setLights(color, 1000, 2000); } builder.setDefaults(defaults); return builder.build(); }
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;/*from w ww .j a v a 2s .co m*/ } 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:co.beem.project.beem.FacebookTextService.java
/** * Show a notification using the preference of the user. * //from www. j a va 2 s .co m * @param id * the id of the notification. * @param notif * the notification to show */ public void sendNotification(int id, Notification notif) { if (mSettings.getBoolean(FacebookTextApplication.NOTIFICATION_VIBRATE_KEY, true)) notif.defaults |= Notification.DEFAULT_VIBRATE; notif.ledARGB = 0xff0000ff; // Blue color notif.ledOnMS = 1000; notif.ledOffMS = 1000; notif.flags |= Notification.FLAG_SHOW_LIGHTS; String ringtoneStr = mSettings.getString(FacebookTextApplication.NOTIFICATION_SOUND_KEY, Settings.System.DEFAULT_NOTIFICATION_URI.toString()); notif.sound = Uri.parse(ringtoneStr); if (mSettings.getBoolean("notifications_new_message", true)) mNotificationManager.notify(id, notif); }
From source file:org.thoughtcrime.SMP.notifications.MessageNotifier.java
private static void setNotificationAlarms(Context context, NotificationCompat.Builder builder, boolean signal, @Nullable Uri ringtone, VibrateState vibrate) { String defaultRingtoneName = TextSecurePreferences.getNotificationRingtone(context); boolean defaultVibrate = TextSecurePreferences.isNotificationVibrateEnabled(context); String ledColor = TextSecurePreferences.getNotificationLedColor(context); String ledBlinkPattern = TextSecurePreferences.getNotificationLedPattern(context); String ledBlinkPatternCustom = TextSecurePreferences.getNotificationLedPatternCustom(context); String[] blinkPatternArray = parseBlinkPattern(ledBlinkPattern, ledBlinkPatternCustom); if (signal && ringtone != null) builder.setSound(ringtone);/* w w w .ja v a 2 s. c o m*/ else if (signal && !TextUtils.isEmpty(defaultRingtoneName)) builder.setSound(Uri.parse(defaultRingtoneName)); else builder.setSound(null); if (signal && (vibrate == VibrateState.ENABLED || (vibrate == VibrateState.DEFAULT && defaultVibrate))) { builder.setDefaults(Notification.DEFAULT_VIBRATE); } if (!ledColor.equals("none")) { builder.setLights(Color.parseColor(ledColor), Integer.parseInt(blinkPatternArray[0]), Integer.parseInt(blinkPatternArray[1])); } }
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;// ww w .j a v a2 s. 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:de.tubs.ibr.dtn.dtalkie.service.TalkieService.java
private void createNotification() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // do not add notifications if autoplay is active if (prefs.getBoolean("autoplay", false) || HeadsetService.ENABLED) return;/* w ww . j ava 2s.c o m*/ // get the number of marked messages int mcount = mDatabase.getMarkedMessageCount(Folder.INBOX, false); // do not add a notification if there is no unread message if (mcount <= 0) return; NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // enable auto-cancel builder.setAutoCancel(true); int defaults = 0; if (prefs.getBoolean("vibrateOnMessage", true)) { defaults |= Notification.DEFAULT_VIBRATE; } /** CREATE AN INTENT TO OPEN THE MESSAGES ACTIVITY **/ Intent resultIntent = new Intent(this, TalkieActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setNumber(mcount); builder.setContentTitle(getResources().getQuantityString(R.plurals.notification_title, mcount)); builder.setContentText(getResources().getQuantityString(R.plurals.notification_text, mcount)); builder.setSmallIcon(R.drawable.ic_mic); builder.setDefaults(defaults); builder.setWhen(System.currentTimeMillis()); builder.setContentIntent(contentIntent); builder.setLights(0xff0080ff, 300, 1000); builder.setSound( Uri.parse(prefs.getString("ringtoneOnMessage", "content://settings/system/notification_sound"))); Notification notification = builder.getNotification(); mNotificationManager.notify(MESSAGE_NOTIFICATION, notification); }