Java Code Examples for android.support.v4.app.NotificationCompat.Builder#setDefaults()
The following examples show how to use
android.support.v4.app.NotificationCompat.Builder#setDefaults() .
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: KlyphNotification.java From Klyph with MIT License | 5 votes |
public static Builder getBuilder(Context context, boolean alert) { Builder builder = new Builder(context).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true); if (alert == true) { int defaults = 0; if (KlyphPreferences.getNotificationRingtone() != null && KlyphPreferences.getNotificationRingtone().equals("default")) { defaults |= android.app.Notification.DEFAULT_SOUND; } else if (KlyphPreferences.getNotificationRingtoneUri() == null) { builder.setSound(null); } else { builder.setSound(Uri.parse(KlyphPreferences.getNotificationRingtoneUri())); } if (KlyphPreferences.isNotificationVibrationEnabled() == true) defaults |= android.app.Notification.DEFAULT_VIBRATE; defaults |= android.app.Notification.DEFAULT_LIGHTS; builder.setDefaults(defaults); builder.setOnlyAlertOnce(true); } return builder; }
Example 2
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 3
Source File: KlyphMessengerNotification.java From KlyphMessenger with MIT License | 5 votes |
public static Builder getBuilder(Context context, boolean alert) { Builder builder = new Builder(context).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setOnlyAlertOnce(!alert); int defaults = 0; if (alert == true) { if (MessengerPreferences.getNotificationRingtone() != null && MessengerPreferences.getNotificationRingtone().equals("default")) { defaults |= android.app.Notification.DEFAULT_SOUND; } else if (MessengerPreferences.getNotificationRingtoneUri() == null) { builder.setSound(null); } else { builder.setSound(Uri.parse(MessengerPreferences.getNotificationRingtoneUri())); } if (MessengerPreferences.isNotificationVibrationEnabled() == true) defaults |= android.app.Notification.DEFAULT_VIBRATE; defaults |= android.app.Notification.DEFAULT_LIGHTS; builder.setDefaults(defaults); } //int defaults = android.app.Notification.DEFAULT_SOUND | android.app.Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); return builder; }
Example 4
Source File: Notifications.java From Onosendai with Apache License 2.0 | 5 votes |
private static void applyStyle (final Builder nb, final NotificationStyle ns) { int defaults = 0; if (ns.isLights()) defaults |= Notification.DEFAULT_LIGHTS; if (ns.isVibrate()) defaults |= Notification.DEFAULT_VIBRATE; if (ns.isSound()) defaults |= Notification.DEFAULT_SOUND; nb.setDefaults(defaults); }
Example 5
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); }