Java Code Examples for android.support.v4.app.NotificationCompat.Builder#setVibrate()
The following examples show how to use
android.support.v4.app.NotificationCompat.Builder#setVibrate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotificationService.java From Conversations with GNU General Public License v3.0 | 5 votes |
private void modifyForSoundVibrationAndLight(Builder mBuilder, boolean notify, boolean quietHours, SharedPreferences preferences) { final Resources resources = mXmppConnectionService.getResources(); final String ringtone = preferences.getString("notification_ringtone", resources.getString(R.string.notification_ringtone)); final boolean vibrate = preferences.getBoolean("vibrate_on_notification", resources.getBoolean(R.bool.vibrate_on_notification)); final boolean led = preferences.getBoolean("led", resources.getBoolean(R.bool.led)); final boolean headsup = preferences.getBoolean("notification_headsup", resources.getBoolean(R.bool.headsup_notifications)); if (notify && !quietHours) { if (vibrate) { final int dat = 70; final long[] pattern = {0, 3 * dat, dat, dat}; mBuilder.setVibrate(pattern); } else { mBuilder.setVibrate(new long[]{0}); } Uri uri = Uri.parse(ringtone); try { mBuilder.setSound(fixRingtoneUri(uri)); } catch (SecurityException e) { Log.d(Config.LOGTAG, "unable to use custom notification sound " + uri.toString()); } } else { mBuilder.setLocalOnly(true); } if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBuilder.setCategory(Notification.CATEGORY_MESSAGE); } mBuilder.setPriority(notify ? (headsup ? NotificationCompat.PRIORITY_HIGH : NotificationCompat.PRIORITY_DEFAULT) : NotificationCompat.PRIORITY_LOW); setNotificationColor(mBuilder); mBuilder.setDefaults(0); if (led) { mBuilder.setLights(LED_COLOR, 2000, 3000); } }
Example 2
Source File: NotificationService.java From Conversations with GNU General Public License v3.0 | 5 votes |
private void modifyIncomingCall(Builder mBuilder) { final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService); final Resources resources = mXmppConnectionService.getResources(); final String ringtone = preferences.getString("call_ringtone", resources.getString(R.string.incoming_call_ringtone)); mBuilder.setVibrate(CALL_PATTERN); final Uri uri = Uri.parse(ringtone); try { mBuilder.setSound(fixRingtoneUri(uri)); } catch (SecurityException e) { Log.d(Config.LOGTAG, "unable to use custom notification sound " + uri.toString()); } mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); setNotificationColor(mBuilder); mBuilder.setLights(LED_COLOR, 2000, 3000); }
Example 3
Source File: AlarmAlertReceiver.java From OmniList with GNU Affero General Public License v3.0 | 4 votes |
private void onAlert(Alarm alarm) { int alarmCode = (int) alarm.getCode(); Assignment assignment = AssignmentsStore.getInstance().get(alarm.getModelCode()); /*If the assignment is null, we don't show notification for it*/ if (assignment == null) { alarmsManager.removeAlarm(alarm); return; } Builder mBuilder = new Builder(context) .setContentTitle(assignment.getName()) .setContentText(assignment.getComment()) .setAutoCancel(true) .setSmallIcon(R.drawable.ic_assignment_turned_in_black_24dp) .setColor(ColorUtils.accentColor()); /*Add action: mark as done.*/ Intent mdIntent = new Intent(context, AlarmAlertReceiver.class); mdIntent.setAction(Constants.ACTION_MARK_ASSIGNMENT_AS_DONE); mdIntent.putExtra(Constants.EXTRA_CODE, assignment.getCode()); mdIntent.putExtra(Constants.EXTRA_NOTIFICATION_ID, (int) alarm.getCode()); PendingIntent piMD = PendingIntent.getBroadcast( context, (int) alarm.getCode(), mdIntent, PendingIntent.FLAG_CANCEL_CURRENT); mBuilder.addAction(R.drawable.ic_check_circle_black_24dp, context.getString(R.string.mark_as_done), piMD); /*Add action: postpone.*/ Intent pIntent = new Intent(context, AlarmAlertReceiver.class); pIntent.setAction(Constants.ACTION_POSTPONE_ALARM); pIntent.putExtra(Constants.EXTRA_CODE, alarm.getCode()); pIntent.putExtra(Constants.EXTRA_NOTIFICATION_ID, (int) alarm.getCode()); PendingIntent piP = PendingIntent.getBroadcast( context, (int) alarm.getCode(), pIntent, PendingIntent.FLAG_UPDATE_CURRENT); int snoozeMinutes = NoticePreferences.getInstance().getSnoozeDuration(); mBuilder.addAction(R.drawable.ic_snooze_black_24dp, String.format(context.getString(R.string.remind_in_minutes), snoozeMinutes), piP); /*Add action: click.*/ Intent clickIntent = new Intent(context, ContentActivity.class); clickIntent.setAction(Constants.ACTION_NOTIFICATION); clickIntent.putExtra(Constants.EXTRA_CODE, assignment.getCode()); clickIntent.putExtra(Constants.EXTRA_FRAGMENT, Constants.VALUE_FRAGMENT_ASSIGNMENT); clickIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity( context, (int) assignment.getCode(), clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(contentIntent); /*Vibrate.*/ if (NoticePreferences.getInstance().isVibrateAllowed()) { mBuilder.setVibrate(getVibrate()); } /*Ringtone.*/ String ringtone = NoticePreferences.getInstance().getNotificationRingtone(); // 铃声 if (ringtone != null){ mBuilder.setSound(Uri.parse(ringtone)); } Notification notification = mBuilder.build(); /*Light.*/ setNotificationLight(notification); notificationManager.notify(alarmCode, notification); }
Example 4
Source File: IMNotificationManager.java From sctalk with Apache License 2.0 | 4 votes |
private void showInNotificationBar(String title,String ticker, Bitmap iconBitmap,int notificationId,Intent intent) { logger.d("notification#showInNotificationBar title:%s ticker:%s",title,ticker); NotificationManager notifyMgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); if (notifyMgr == null) { return; } Builder builder = new NotificationCompat.Builder(ctx); builder.setContentTitle(title); builder.setContentText(ticker); builder.setSmallIcon(R.drawable.tt_small_icon); builder.setTicker(ticker); builder.setWhen(System.currentTimeMillis()); builder.setAutoCancel(true); // this is the content near the right bottom side // builder.setContentInfo("content info"); if (configurationSp.getCfg(SysConstant.SETTING_GLOBAL,ConfigurationSp.CfgDimension.VIBRATION)) { // delay 0ms, vibrate 200ms, delay 250ms, vibrate 200ms long[] vibrate = {0, 200, 250, 200}; builder.setVibrate(vibrate); } else { logger.d("notification#setting is not using vibration"); } // sound if (configurationSp.getCfg(SysConstant.SETTING_GLOBAL,ConfigurationSp.CfgDimension.SOUND)) { builder.setDefaults(Notification.DEFAULT_SOUND); } else { logger.d("notification#setting is not using sound"); } if (iconBitmap != null) { logger.d("notification#fetch icon from network ok"); builder.setLargeIcon(iconBitmap); } else { // do nothint ? } // if MessageActivity is in the background, the system would bring it to // the front intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(ctx, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); Notification notification = builder.build(); notifyMgr.notify(notificationId, notification); }
Example 5
Source File: KlyphNotification.java From Klyph with MIT License | 4 votes |
public static void setNoVibration(Builder builder) { builder.setVibrate(null); }
Example 6
Source File: KlyphMessengerNotification.java From KlyphMessenger with MIT License | 4 votes |
public static void setNoVibration(Builder builder) { builder.setVibrate(null); }