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:me.trashout.service.TrashHunterService.java
private void createNotification(int trashCount, int trashHunterArea) { Log.d("TrashHunter", ".....createNotification..... trashHunterArea - " + trashHunterArea); Intent viewIntent = BaseActivity.generateIntent(this, TrashListFragment.class.getName(), TrashListFragment.generateBundle(true, trashHunterArea), MainActivity.class); viewIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); Context context = getBaseContext(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(getNotificationIcon()) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)) .setContentTitle(context.getString(R.string.app_name)) .setContentText(String.format(getString(R.string.notification_new_trash_formatter), trashCount)) .setAutoCancel(true).setContentIntent(viewPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notif = mBuilder.build(); notif.defaults |= Notification.DEFAULT_SOUND; notif.defaults |= Notification.DEFAULT_VIBRATE; mNotificationManager.notify(NOTIFICATION_ID, notif); }
From source file:com.xabber.android.data.notification.NotificationManager.java
/** * Sound, vibration and lightning flags. * * @param notificationBuilder/*w ww.j av a 2 s. co m*/ * @param streamType */ public void setNotificationDefaults(NotificationCompat.Builder notificationBuilder, boolean vibration, Uri sound, int streamType) { notificationBuilder.setSound(sound, streamType); notificationBuilder.setDefaults(0); int defaults = 0; if (vibration) { if (SettingsManager.eventsIgnoreSystemVibro()) { startVibration(); } else { defaults |= Notification.DEFAULT_VIBRATE; } } if (SettingsManager.eventsLightning()) { defaults |= Notification.DEFAULT_LIGHTS; } notificationBuilder.setDefaults(defaults); }
From source file:org.fdroid.enigtext.notifications.MessageNotifier.java
private static void setNotificationAlarms(Context context, NotificationCompat.Builder builder, boolean signal) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); String ringtone = sp.getString(ApplicationPreferencesActivity.RINGTONE_PREF, null); boolean vibrate = sp.getBoolean(ApplicationPreferencesActivity.VIBRATE_PREF, true); String ledColor = sp.getString(ApplicationPreferencesActivity.LED_COLOR_PREF, "green"); String ledBlinkPattern = sp.getString(ApplicationPreferencesActivity.LED_BLINK_PREF, "500,2000"); String ledBlinkPatternCustom = sp.getString(ApplicationPreferencesActivity.LED_BLINK_PREF_CUSTOM, "500,2000"); String[] blinkPatternArray = parseBlinkPattern(ledBlinkPattern, ledBlinkPatternCustom); builder.setSound(TextUtils.isEmpty(ringtone) || !signal ? null : Uri.parse(ringtone)); if (signal && vibrate) builder.setDefaults(Notification.DEFAULT_VIBRATE); builder.setLights(Color.parseColor(ledColor), Integer.parseInt(blinkPatternArray[0]), Integer.parseInt(blinkPatternArray[1])); }
From source file:com.android.messaging.receiver.SmsReceiver.java
public static void postNewMessageSecondaryUserNotification() { final Context context = Factory.get().getApplicationContext(); final Resources resources = context.getResources(); final PendingIntent pendingIntent = UIIntents.get() .getPendingIntentForSecondaryUserNewMessageNotification(context); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle(resources.getString(R.string.secondary_user_new_message_title)) .setTicker(resources.getString(R.string.secondary_user_new_message_ticker)) .setSmallIcon(R.drawable.ic_sms_light) // Returning PRIORITY_HIGH causes L to put up a HUD notification. Without it, the ticker // isn't displayed. .setPriority(Notification.PRIORITY_HIGH).setContentIntent(pendingIntent); final NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(builder); bigTextStyle.bigText(resources.getString(R.string.secondary_user_new_message_title)); final Notification notification = bigTextStyle.build(); final NotificationManagerCompat notificationManager = NotificationManagerCompat .from(Factory.get().getApplicationContext()); int defaults = Notification.DEFAULT_LIGHTS; if (BugleNotifications.shouldVibrate(new SecondaryUserNotificationState())) { defaults |= Notification.DEFAULT_VIBRATE; }//from ww w .ja v a2 s. co m notification.defaults = defaults; notificationManager.notify(getNotificationTag(), PendingIntentConstants.SMS_SECONDARY_USER_NOTIFICATION_ID, notification); }
From source file:de.tubs.ibr.dtn.chat.service.ChatService.java
@SuppressWarnings("deprecation") private void showNotification(Intent intent) { int defaults = 0; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getBoolean("vibrateOnMessage", true)) { defaults |= Notification.DEFAULT_VIBRATE; }//ww w. j a va2 s . com Long buddyId = intent.getLongExtra(EXTRA_BUDDY_ID, -1L); String displayName = intent.getStringExtra(EXTRA_DISPLAY_NAME); String textBody = intent.getStringExtra(EXTRA_TEXT_BODY); CharSequence tickerText = getString(R.string.new_message_from) + " " + displayName; CharSequence contentTitle = getString(R.string.new_message); CharSequence contentText = displayName + ":\n" + textBody; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // forward intent to the activity intent.setClass(this, MainActivity.class); // Adds the intent to the main view stackBuilder.addNextIntent(intent); // Gets a PendingIntent containing the entire back stack PendingIntent contentIntent = stackBuilder.getPendingIntent(buddyId.intValue(), PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(contentTitle); builder.setContentText(contentText); builder.setSmallIcon(R.drawable.ic_message); builder.setTicker(tickerText); builder.setDefaults(defaults); builder.setWhen(System.currentTimeMillis()); builder.setContentIntent(contentIntent); builder.setLights(0xffff0000, 300, 1000); builder.setSound( Uri.parse(prefs.getString("ringtoneOnMessage", "content://settings/system/notification_sound"))); builder.setAutoCancel(true); Notification notification = builder.getNotification(); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(buddyId.toString(), MESSAGE_NOTIFICATION, notification); if (prefs.getBoolean("ttsWhenOnHeadset", false)) { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (am.isBluetoothA2dpOn() || am.isWiredHeadsetOn()) { // speak the notification Intent tts_intent = new Intent(this, TTSService.class); tts_intent.setAction(TTSService.INTENT_SPEAK); tts_intent.putExtra("speechText", tickerText + ": " + textBody); startService(tts_intent); } } }
From source file:com.psiphon3.psiphonlibrary.TunnelManager.java
private Notification createNotification(boolean alert) { int contentTextID; int iconID;//www.ja va 2 s . c om CharSequence ticker = null; if (m_tunnelState.isConnected) { if (m_tunnelConfig.wholeDevice) { contentTextID = R.string.psiphon_running_whole_device; } else { contentTextID = R.string.psiphon_running_browser_only; } iconID = R.drawable.notification_icon_connected; } else { contentTextID = R.string.psiphon_service_notification_message_connecting; ticker = m_parentService.getText(R.string.psiphon_service_notification_message_connecting); iconID = R.drawable.notification_icon_connecting_animation; } mNotificationBuilder.setSmallIcon(iconID).setContentTitle(m_parentService.getText(R.string.app_name)) .setContentText(m_parentService.getText(contentTextID)).setTicker(ticker) .setContentIntent(m_tunnelConfig.notificationPendingIntent); Notification notification = mNotificationBuilder.build(); if (alert) { final AppPreferences multiProcessPreferences = new AppPreferences(getContext()); if (multiProcessPreferences .getBoolean(m_parentService.getString(R.string.preferenceNotificationsWithSound), false)) { notification.defaults |= Notification.DEFAULT_SOUND; } if (multiProcessPreferences .getBoolean(m_parentService.getString(R.string.preferenceNotificationsWithVibrate), false)) { notification.defaults |= Notification.DEFAULT_VIBRATE; } } return notification; }
From source file:com.mattprecious.notisync.service.SecondaryService.java
private void handleTextMessage(TextMessage message) { if (!Preferences.getSecondaryTextMessageEnabled(this)) { return;//from w w w .j a v a 2s .co m } if (textMessages.containsKey(message.number)) { List<TextMessage> messages = textMessages.remove(message.number); messages.add(message); textMessages.put(message.number, messages); } else { List<TextMessage> list = Lists.newArrayList(); list.add(message); textMessages.put(message.number, list); } NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_stat_sms); builder.setSound(getRingtoneUri(Preferences.getSecondaryTextMessageRingtone(this))); builder.setAutoCancel(true); int defaults = 0; if (Preferences.getSecondaryTextMessageVibrate(this)) { defaults |= Notification.DEFAULT_VIBRATE; } if (Preferences.getSecondaryTextMessageLights(this)) { defaults |= Notification.DEFAULT_LIGHTS; } builder.setDefaults(defaults); PendingIntent deleteIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_TEXT_NOTIFICATION_DELETED), 0); builder.setContentIntent(deleteIntent); builder.setDeleteIntent(deleteIntent); List<List<NotificationData>> threadList = Lists.newArrayList(); List<Entry<String, List<TextMessage>>> entryList = Lists .reverse(Lists.newArrayList(textMessages.entrySet())); for (Entry<String, List<TextMessage>> entry : entryList) { List<TextMessage> messages = entry.getValue(); TextMessage last = messages.get(messages.size() - 1); String sender; if (last.name != null) { sender = last.name; } else { sender = PhoneNumberUtils.formatNumber(last.number); } List<NotificationData> data = Lists.newArrayList(); for (TextMessage msg : messages) { data.add(new NotificationData(sender, msg.message)); } threadList.add(data); } Bitmap photo = ContactHelper.getContactPhoto(this, message.number); notificationManager.notify(NOTIFICATION_ID_TEXT, buildRichNotification(builder, threadList, photo)); String sender; if (message.name != null) { sender = message.name; } else { sender = PhoneNumberUtils.formatNumber(message.number); } openNotificationDatabaseWrite(); notificationsDbAdapter.insertNotification("text.message", "smsmms", "SMS/MMS", sender, PhoneNumberUtils.formatNumber(message.number), System.currentTimeMillis() + ""); notificationsDbAdapter.close(); }
From source file:com.google.android.apps.paco.NotificationCreator.java
private Notification createNotification(Context context, Experiment experiment, NotificationHolder notificationHolder, String message) { int icon = R.drawable.paco32; String tickerText = context.getString(R.string.time_for_notification_title) + experiment.getTitle(); if (notificationHolder.isCustomNotification()) { tickerText = message;/*from w w w. ja v a 2 s . com*/ } //Notification notification = new Notification(icon, tickerText, notificationHolder.getAlarmTime()); Intent surveyIntent = new Intent(context, ExperimentExecutor.class); surveyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); Uri uri = Uri.withAppendedPath(ExperimentColumns.JOINED_EXPERIMENTS_CONTENT_URI, experiment.getId().toString()); surveyIntent.setData(uri); surveyIntent.putExtra(Experiment.SCHEDULED_TIME, notificationHolder.getAlarmTime()); surveyIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue()); PendingIntent notificationIntent = PendingIntent.getActivity(context, 1, surveyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // new wearable compatible way to do it NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context).setSmallIcon(icon) .setContentTitle(experiment.getTitle()).setTicker(tickerText).setContentText(message) .setWhen(notificationHolder.getAlarmTime()).setContentIntent(notificationIntent) .setAutoCancel(true); int defaults = Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS; String ringtoneUri = new UserPreferences(context).getRingtone(); if (ringtoneUri != null) { notificationBuilder.setSound(Uri.parse(ringtoneUri)); } else { defaults |= Notification.DEFAULT_SOUND; // notification.sound = Uri.parse(android.os.Environment.getExternalStorageDirectory().getAbsolutePath() // + "/Android/data/" + context.getPackageName() + "/" + // "deepbark_trial.mp3"); } notificationBuilder.setDefaults(defaults); //end wearable return notificationBuilder.build(); }
From source file:org.numixproject.hermes.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 * @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 *//* w ww . j a va2 s . c o m*/ private void updateNotification(String text, String contentText, boolean vibrate, boolean sound, boolean light) { Intent disconnect = new Intent("disconnect_all"); PendingIntent pendingIntentDisconnect = PendingIntent.getBroadcast(this, 0, disconnect, PendingIntent.FLAG_CANCEL_CURRENT); if (foreground) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentText(text); builder.setSmallIcon(R.drawable.ic_stat_hermes2); builder.setWhen(System.currentTimeMillis()); builder.addAction(R.drawable.ic_action_ic_close_24px, "DISCONNECT ALL", pendingIntentDisconnect); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setColor(Color.parseColor("#0097A7")); } Intent notifyIntent = new Intent(this, MainActivity.class); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0); 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)); } 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); } } builder.setContentIntent(contentIntent).setWhen(System.currentTimeMillis()) .setContentTitle(getText(R.string.app_name)).setContentText(contentText); Notification notification = builder.build(); if (vibrate) { notification.defaults |= Notification.DEFAULT_VIBRATE; } if (sound) { notification.defaults |= Notification.DEFAULT_SOUND; } 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:org.mariotaku.twidere.provider.TweetStoreProvider.java
private Notification buildNotification(final NotificationCompat.Builder builder, final String ticker, final String title, final String message, final int icon, final Bitmap large_icon, final Intent content_intent, final Intent delete_intent) { final Context context = getContext(); builder.setTicker(ticker);/*from w w w.ja va 2 s. c om*/ builder.setContentTitle(title); builder.setContentText(message); builder.setAutoCancel(true); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(icon); if (large_icon != null) { builder.setLargeIcon(large_icon); } if (delete_intent != null) { builder.setDeleteIntent( PendingIntent.getBroadcast(context, 0, delete_intent, PendingIntent.FLAG_UPDATE_CURRENT)); } if (content_intent != null) { builder.setContentIntent( PendingIntent.getActivity(context, 0, content_intent, PendingIntent.FLAG_UPDATE_CURRENT)); } int defaults = 0; final Calendar now = Calendar.getInstance(); if (mNotificationIsAudible && !mPreferences.getBoolean("slient_notifications_at_" + now.get(Calendar.HOUR_OF_DAY), false)) { 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 = context.getResources().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(); }