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:com.akop.bach.service.XboxLiveServiceClient.java
private void notifyBeacons(XboxLiveAccount account, HashMap<String, long[]> matching, HashMap<String, long[]> lastMatching) { Context context = getContext(); NotificationManager mgr = getNotificationManager(); if (App.getConfig().logToConsole()) { if (lastMatching != null && lastMatching.size() > 0) { App.logv("Last matching:"); for (String key : lastMatching.keySet()) { String s = "* BEACONS " + key + ": "; for (long friendId : lastMatching.get(key)) s += friendId + ","; App.logv(s);/*from w w w . j av a 2 s. c om*/ } } if (matching.size() > 0) { App.logv("Now matching:"); for (String key : matching.keySet()) { String s = "* BEACONS " + key + ": "; for (long friendId : matching.get(key)) s += friendId + ","; App.logv(s); } } } int notificationId = 0x40000 | (((int) account.getId() & 0xfff) << 4); String[] gameUids = new String[matching.keySet().size()]; matching.keySet().toArray(gameUids); for (int i = 0; i < MAX_BEACONS; i++) { if (i < gameUids.length) { String gameUid = gameUids[i]; long[] matchingFriends = matching.get(gameUid); if (!lastMatching.containsKey(gameUid) || !areArraysEquivalent(matchingFriends, lastMatching.get(gameUid))) { if (matchingFriends.length > 0) { String title = XboxLive.Games.getTitle(context, account, gameUid); String message = null; String ticker = null; int iconOverlayNumber = 0; Intent intent = null; if (matchingFriends.length > 1) { iconOverlayNumber = matchingFriends.length; intent = new Intent(context, FriendList.class); intent.putExtra("account", account); ticker = context.getString(R.string.friends_playing_beaconed_game_title_f, matchingFriends.length, title); message = context.getString(R.string.friends_playing_beaconed_game_f, matchingFriends.length, account.getDescription()); } else { String friendScreenName = Friends.getGamertag(context, matchingFriends[0]); intent = account.getFriendIntent(context, friendScreenName); ticker = context.getString(R.string.friend_playing_beaconed_game_title_f, friendScreenName, title); message = context.getString(R.string.friend_playing_beaconed_game_f, friendScreenName, account.getDescription()); } NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)) .setSmallIcon(R.drawable.xbox_stat_notify_beacon).setContentTitle(title) .setContentText(message).setTicker(ticker).setWhen(System.currentTimeMillis()) .setAutoCancel(true).setOnlyAlertOnce(true).setNumber(iconOverlayNumber) .setLights(DEFAULT_LIGHTS_COLOR, DEFAULT_LIGHTS_ON_MS, DEFAULT_LIGHTS_OFF_MS) .setSound(account.getRingtoneUri()); if (account.isVibrationEnabled()) builder.setDefaults(Notification.DEFAULT_VIBRATE); Notification notification = builder.getNotification(); mgr.notify(notificationId, notification); } else { mgr.cancel(notificationId); } } } else { mgr.cancel(notificationId); } notificationId++; } }
From source file:com.landenlabs.all_devtool.PackageFragment.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from w ww .j av a 2 s . c om */ private void sendNotification(Context context, String from, String message) { /* Intent intent = new Intent(context, DevToolActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT); */ Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.shortcut_pkg).setContentTitle("Uninstalled").setContentText(message) .setAutoCancel(true); // .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }) // .setLights(Color.RED, 3000, 3000) // .setSound(defaultSoundUri) // .setSound(Settings.System.DEFAULT_NOTIFICATION_URI) // .setContentIntent(pendingIntent); // <uses-permission android:name="android.permission.VIBRATE" /> Notification note = notificationBuilder.build(); note.defaults |= Notification.DEFAULT_VIBRATE; note.defaults |= Notification.DEFAULT_SOUND; note.defaults |= Notification.DEFAULT_LIGHTS; NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, note); }
From source file:gwind.windalarm.MyFirebaseMessagingService.java
public static void xnotifyUser(Context context, String header, String message, String spotId) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Activity.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context.getApplicationContext(), SplashActivity.class); notificationIntent.putExtra("spotId", spotId); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(notificationIntent); PendingIntent pIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new Notification.Builder(context).setContentTitle(header) .setContentText(message).setContentIntent(pIntent) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE).setContentIntent(pIntent) .setAutoCancel(true).setSmallIcon(R.drawable.logo).build(); // mId allows you to update the notification later on. int mId = 2;/* w ww.j a va2 s . co m*/ notificationManager.notify(mId, notification); }
From source file:org.chromium.chrome.browser.notifications.NotificationUIManager.java
/** * Generates the notfiication defaults from vibrationPattern's size and silent. * * Use the system's default ringtone, vibration and indicator lights unless the notification * has been marked as being silent./* w ww.ja va 2 s .c o m*/ * If a vibration pattern is set, the notification should use the provided pattern * rather than the defaulting to system settings. * * @param vibrationPatternLength Vibration pattern's size for the Notification. * @param silent Whether the default sound, vibration and lights should be suppressed. * @return The generated notification's default value. */ @VisibleForTesting static int makeDefaults(int vibrationPatternLength, boolean silent) { assert !silent || vibrationPatternLength == 0; if (silent) return 0; int defaults = Notification.DEFAULT_ALL; if (vibrationPatternLength > 0) { defaults &= ~Notification.DEFAULT_VIBRATE; } return defaults; }
From source file:am.roadpolice.roadpolice.alarm.AlarmReceiver.java
@Override public void submissionCompleted(ArrayList<ViolationInfo> list, String result) { // If errors occurs while trying to update data. if (!TextUtils.isEmpty(result)) { final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences.Editor ed = sp.edit(); ed.putBoolean(MainActivity.MISS_UPDATE_DUE_TO_NETWORK_ISSUE, true); ed.apply();//from ww w .ja va 2s. c o m return; } SQLiteHelper dbHelper = new SQLiteHelper(mContext); // Get list of new violation info, if null no new items found. ArrayList<ViolationInfo> newViolationInfoList = dbHelper.insertViolationInfoListAndCheckNew(list); // Create notification. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext); // Create notification Title Text. int updateInterval = DialogSettings.getUpdateInterval(mContext); switch (updateInterval) { case DialogSettings.DAILY: mBuilder.setContentTitle(mContext.getString(R.string.txtDailyNotification)); break; case DialogSettings.WEEKLY: mBuilder.setContentTitle(mContext.getString(R.string.txtWeeklyNotification)); break; case DialogSettings.MONTHLY: mBuilder.setContentTitle(mContext.getString(R.string.txtMonthlyNotification)); break; } // Create notification message. if (newViolationInfoList == null || newViolationInfoList.size() < 1) { mBuilder.setContentText(mContext.getString(R.string.txtNoViolationNotification)); mBuilder.setSmallIcon(R.drawable.ic_checked); } else { mBuilder.setContentText(mContext.getString(R.string.txtYesViolationNotification)); mBuilder.setSmallIcon(R.drawable.ic_attention); } // Activate vibration and sound. mBuilder.setDefaults(Notification.DEFAULT_SOUND); mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); mBuilder.setAutoCancel(true); // Set intent to open Main Activity, when user click on notification. Intent notificationIntent = new Intent(mContext, MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent mainActivityPendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0); mBuilder.setContentIntent(mainActivityPendingIntent); // Show notification. NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, mBuilder.build()); // Get shared preferences. SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences.Editor ed = sp.edit(); ed.putBoolean(MainActivity.MISS_UPDATE_DUE_TO_NETWORK_ISSUE, false); ed.apply(); }
From source file:com.twofours.surespot.services.SurespotGcmListenerService.java
private void generateNotification(Context context, String type, String from, String to, String title, String message, String tag, int id) { SurespotLog.d(TAG, "generateNotification"); // get shared prefs SharedPreferences pm = context.getSharedPreferences(to, Context.MODE_PRIVATE); if (!pm.getBoolean("pref_notifications_enabled", true)) { return;/*from www . j a v a 2s .c o m*/ } int icon = R.drawable.surespot_logo; // need to use same builder for only alert once to work: // http://stackoverflow.com/questions/6406730/updating-an-ongoing-notification-quietly mBuilder.setSmallIcon(icon).setContentTitle(title).setAutoCancel(true).setOnlyAlertOnce(false) .setContentText(message); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); Intent mainIntent = null; mainIntent = new Intent(context, MainActivity.class); mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); mainIntent.putExtra(SurespotConstants.ExtraNames.MESSAGE_TO, to); mainIntent.putExtra(SurespotConstants.ExtraNames.MESSAGE_FROM, from); mainIntent.putExtra(SurespotConstants.ExtraNames.NOTIFICATION_TYPE, type); stackBuilder.addNextIntent(mainIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent((int) new Date().getTime(), PendingIntent.FLAG_CANCEL_CURRENT); mBuilder.setContentIntent(resultPendingIntent); int defaults = 0; boolean showLights = pm.getBoolean("pref_notifications_led", true); boolean makeSound = pm.getBoolean("pref_notifications_sound", true); boolean vibrate = pm.getBoolean("pref_notifications_vibration", true); int color = pm.getInt("pref_notification_color", getResources().getColor(R.color.surespotBlue)); if (showLights) { SurespotLog.v(TAG, "showing notification led"); mBuilder.setLights(color, 500, 5000); defaults |= Notification.FLAG_SHOW_LIGHTS; // shouldn't need this - setLights does it. Just to make sure though... } else { mBuilder.setLights(color, 0, 0); } if (makeSound) { SurespotLog.v(TAG, "making notification sound"); defaults |= Notification.DEFAULT_SOUND; } if (vibrate) { SurespotLog.v(TAG, "vibrating notification"); defaults |= Notification.DEFAULT_VIBRATE; } mBuilder.setDefaults(defaults); mNotificationManager.notify(tag, id, mBuilder.build()); }
From source file:com.twofours.surespot.services.SurespotGcmListenerService.java
private void generateSystemNotification(Context context, String title, String message, String tag, int id) { // need to use same builder for only alert once to work: // http://stackoverflow.com/questions/6406730/updating-an-ongoing-notification-quietly mBuilder.setAutoCancel(true).setOnlyAlertOnce(true); int defaults = 0; mBuilder.setLights(0xff0000FF, 500, 5000); defaults |= Notification.DEFAULT_SOUND; defaults |= Notification.DEFAULT_VIBRATE; mBuilder.setDefaults(defaults);/*www .j a v a 2s . c om*/ PendingIntent contentIntent = PendingIntent.getActivity(context, (int) new Date().getTime(), new Intent(), PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = UIUtils.generateNotification(mBuilder, contentIntent, getPackageName(), title, message); mNotificationManager.notify(tag, id, notification); }
From source file:org.kontalk.ui.MessagingNotification.java
private static void setDefaults(Context context, NotificationCompat.Builder builder) { int defaults = 0; if (Preferences.getNotificationLED(context)) { int ledColor = Preferences.getNotificationLEDColor(context); builder.setLights(ledColor, 1000, 1000); } else {//w w w. j ava 2s .c o m // this will disable the LED completely builder.setLights(0, 0, 0); } String ringtone = Preferences.getNotificationRingtone(context); if (ringtone != null && ringtone.length() > 0) builder.setSound(Uri.parse(ringtone)); String vibrate = Preferences.getNotificationVibrate(context); if ("always".equals(vibrate) || ("silent_only".equals(vibrate) && ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE)) .getRingerMode() != AudioManager.RINGER_MODE_NORMAL)) defaults |= Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); }
From source file:org.thoughtcrime.securesms.notifications.MessageNotifier.java
private static void setNotificationAlarms(Context context, NotificationCompat.Builder builder, boolean signal) { String ringtone = TextSecurePreferences.getNotificationRingtone(context); boolean vibrate = TextSecurePreferences.isNotificationVibrateEnabled(context); String ledColor = TextSecurePreferences.getNotificationLedColor(context); String ledBlinkPattern = TextSecurePreferences.getNotificationLedPattern(context); String ledBlinkPatternCustom = TextSecurePreferences.getNotificationLedPatternCustom(context); 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.securecomcode.text.notifications.MessageNotifier.java
private static void setNotificationAlarms(Context context, NotificationCompat.Builder builder, boolean signal) { String ringtone = TextSecurePreferences.getNotificationRingtone(context); boolean vibrate = TextSecurePreferences.isNotificationVibrateEnabled(context); String ledColor = TextSecurePreferences.getNotificationLedColor(context); String ledBlinkPattern = TextSecurePreferences.getNotificationLedPattern(context); String ledBlinkPatternCustom = TextSecurePreferences.getNotificationLedPatternCustom(context); String[] blinkPatternArray = parseBlinkPattern(ledBlinkPattern, ledBlinkPatternCustom); builder.setSound(TextUtils.isEmpty(ringtone) || !signal ? null : Uri.parse(ringtone)); if (signal && vibrate) { builder.setDefaults(Notification.DEFAULT_VIBRATE); }//from w ww . j a va 2 s .com if (!ledColor.equals("none")) { builder.setLights(Color.parseColor(ledColor), Integer.parseInt(blinkPatternArray[0]), Integer.parseInt(blinkPatternArray[1])); } }