List of usage examples for android.app Notification DEFAULT_SOUND
int DEFAULT_SOUND
To view the source code for android.app Notification DEFAULT_SOUND.
Click Source Link
From source file:com.vendsy.bartsy.venue.BartsyApplication.java
private void generateNotification(final String title, final String body, final int count) { mHandler.post(new Runnable() { public void run() { // Get app icon bitmap and scale to fit in notification Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); largeIcon = Bitmap.createScaledBitmap(largeIcon, NOTIFICATION_IMAGE_SIZE, NOTIFICATION_IMAGE_SIZE, true);//from ww w.ja v a2 s . c om NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setLargeIcon(largeIcon).setSmallIcon(R.drawable.ic_launcher).setContentTitle(title) .setContentText(body); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext()); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setNumber(count); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Play default notification sound mBuilder.setDefaults(Notification.DEFAULT_SOUND); // mId allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); } }); }
From source file:org.linphone.compatibility.ApiFivePlus.java
public static Notification createMessageNotification(Context context, String title, String msg, PendingIntent intent) {/*w ww . ja v a2 s . c o m*/ NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.chat_icon_over).setContentTitle(title).setContentText(msg) .setContentIntent(intent); Notification notif = notifBuilder.build(); notif.defaults |= Notification.DEFAULT_VIBRATE; notif.defaults |= Notification.DEFAULT_SOUND; notif.defaults |= Notification.DEFAULT_LIGHTS; return notif; }
From source file:com.uphyca.idobata.android.service.IdobataService.java
private Notification buildNotification(PendingIntent pi, CharSequence title, CharSequence text) { int vibrate = mNotificationEffectsVibratePref.get() ? Notification.DEFAULT_VIBRATE : 0; int ledFlash = mNotificationEffectsLEDFlashPref.get() ? Notification.DEFAULT_LIGHTS : 0; int sound = mNotificationEffectsSoundPref.get() ? Notification.DEFAULT_SOUND : 0; NotificationCompat.Builder builder = new NotificationCompat.Builder(IdobataService.this) .setSmallIcon(R.drawable.ic_stat_notification).setContentTitle(title).setContentText(text) .setTicker(new StringBuilder(title).append(' ').append(text)).setAutoCancel(true) .setContentIntent(pi).setDefaults(vibrate | sound | ledFlash); if (ledFlash != 0) { builder.setLights(0xFF00FF00, 200, 1000); }//from w ww .ja v a 2 s.c om return builder.build(); }
From source file:com.android.screenspeak.ScreenSpeakUpdateHelper.java
private Notification buildGestureChangeNotification(Intent clickIntent) { final PendingIntent pendingIntent = PendingIntent.getActivity(mService, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); final String ticker = mService.getString(R.string.notification_title_screenspeak_gestures_changed); final String contentTitle = mService.getString(R.string.notification_title_screenspeak_gestures_changed); final String contentText = mService.getString(R.string.notification_message_screenspeak_gestures_changed); final Notification notification = new NotificationCompat.Builder(mService) .setSmallIcon(R.drawable.ic_stat_info).setTicker(ticker).setContentTitle(contentTitle) .setContentText(contentText).setContentIntent(pendingIntent).setAutoCancel(false).setWhen(0) .build();//from w w w . jav a 2s. c om notification.defaults |= Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_ONGOING_EVENT; return notification; }
From source file:com.onesignal.GenerateNotification.java
private static NotificationCompat.Builder getBaseNotificationCompatBuilder(JSONObject gcmBundle, boolean notify) { int notificationIcon = getSmallIconId(gcmBundle); int notificationDefaults = 0; if (OneSignal.getVibrate(currentContext)) notificationDefaults = Notification.DEFAULT_VIBRATE; String message = null;//www . j a v a2 s. c o m try { message = gcmBundle.getString("alert"); } catch (Throwable t) { } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(currentContext).setAutoCancel(true) .setSmallIcon(notificationIcon) // Small Icon required or notification doesn't display .setContentTitle(getTitle(gcmBundle)) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message); if (notify) notifBuilder.setTicker(message); // Android 5.0 accent color to use, only works when AndroidManifest.xml is // targetSdkVersion >= 21 if (gcmBundle.has("bgac")) { try { notifBuilder.setColor(new BigInteger(gcmBundle.getString("bgac"), 16).intValue()); } catch (Throwable t) { } // Can throw if an old android support lib is used or parse error. } BigInteger ledColor = null; if (notify && gcmBundle.has("ledc")) { try { ledColor = new BigInteger(gcmBundle.getString("ledc"), 16); notifBuilder.setLights(ledColor.intValue(), 2000, 5000); } catch (Throwable t) { notificationDefaults |= Notification.DEFAULT_LIGHTS; } // Can throw if an old android support lib is used or parse error. } else notificationDefaults |= Notification.DEFAULT_LIGHTS; try { int visibility = Notification.VISIBILITY_PUBLIC; if (gcmBundle.has("vis")) visibility = Integer.parseInt(gcmBundle.getString("vis")); notifBuilder.setVisibility(visibility); } catch (Throwable t) { } // Can throw if an old android support lib is used or parse error Bitmap largeIcon = getLargeIcon(gcmBundle); if (largeIcon != null) notifBuilder.setLargeIcon(largeIcon); Bitmap bigPictureIcon = getBitmapIcon(gcmBundle, "bicon"); if (bigPictureIcon != null) notifBuilder.setStyle( new NotificationCompat.BigPictureStyle().bigPicture(bigPictureIcon).setSummaryText(message)); if (notify && OneSignal.getSoundEnabled(currentContext)) { Uri soundUri = getCustomSound(gcmBundle); if (soundUri != null) notifBuilder.setSound(soundUri); else notificationDefaults |= Notification.DEFAULT_SOUND; } if (!notify) notificationDefaults = 0; notifBuilder.setDefaults(notificationDefaults); return notifBuilder; }
From source file:com.mobileman.moments.android.frontend.activity.IncomingCallActivity.java
private void sendNotificationAndFinish() { if (streamingUser != null) { Intent intent = new Intent(getApplicationContext(), MediaPlayerActivity.class); Bundle extras = new Bundle(); extras.putString(MediaPlayerActivity.MEDIA_URL, streamingUser.getStream().getFullVideoUrl()); extras.putString(MediaPlayerActivity.THUMBNAIL_URL, streamingUser.getStream().getFullThumbnailUrl()); extras.putString(MediaPlayerActivity.USER_ID, streamingUser.getUuid()); intent.putExtras(extras);/*from www . j a v a2 s . c o m*/ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder b = new NotificationCompat.Builder(getApplicationContext()); String notificationTitle = userName + " " + getResources().getString(R.string.isLiveSuffix); String notificationText = "";// getResources().getString(R.string.missedCallNotification) + " " + streamingUser.getName(); String mediaUrl = streamingUser.getStream().getFullVideoUrl(); if ((streamingUser.getStream() != null) && (streamingUser.getStream().getTitle() != null)) { notificationText = streamingUser.getStream().getTitle(); //notificationText + "(" + streamingUser.getStream().getTitle() + ")"; } ImageView incomingCallUserImageView = (ImageView) findViewById(R.id.incomingCallUserImageView); Bitmap bitmap = ((BitmapDrawable) incomingCallUserImageView.getDrawable()).getBitmap(); NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); b.setAutoCancel(true).setSmallIcon(R.drawable.ic_launcher).setDefaults(Notification.DEFAULT_ALL) .setWhen(System.currentTimeMillis()).setTicker("X").setContentTitle(notificationTitle) .setContentText(notificationText) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND) .setContentIntent(contentIntent); // if (bitmap != null) { // b.setLargeIcon(bitmap); // } NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(++NOTIFICATION_COUNTER, b.build()); } finish(); }
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.psiphon3.psiphonlibrary.TunnelManager.java
private Notification createNotification(boolean alert) { int contentTextID; int iconID;// w w w .j ava2 s . com 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:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java
private void oldPushNotification(Context context, Intent intent) { PushReportUtility.log("oldPushNotification->isForground = " + EBrowserActivity.isForground); if (EBrowserActivity.isForground) { if (mContext != null) { intent.putExtra("ntype", F_TYPE_PUSH); ((EBrowserActivity) mContext).handleIntent(intent); }//from w w w . ja v a2 s . c o m } else { CharSequence tickerText = intent.getStringExtra("title"); // ???? Resources res = context.getResources(); int icon = res.getIdentifier("icon", "drawable", intent.getPackage()); long when = System.currentTimeMillis(); // ? // ??Nofification String notifyTitle = null; String pushMessage = intent.getStringExtra("message"); String value = intent.getStringExtra("data"); // ??json try { JSONObject bodyJson = new JSONObject(value); notifyTitle = bodyJson.getString("msgName");// ? } catch (Exception e) { PushReportUtility.oe("onReceive", e); } if (TextUtils.isEmpty(notifyTitle)) { notifyTitle = intent.getStringExtra("widgetName");// msgNamewidgetName? } if (TextUtils.isEmpty(notifyTitle)) { notifyTitle = "APPCAN";// widgetNameAPPCAN? } CharSequence contentTitle = notifyTitle; // ? Intent notificationIntent = new Intent(context, EBrowserActivity.class); // ??Activity notificationIntent.putExtra("data", value); notificationIntent.putExtra("message", pushMessage); notificationIntent.putExtra("ntype", F_TYPE_PUSH); String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); Notification notification = new Notification(icon, tickerText, when); notification.flags = Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND; if (Build.VERSION.SDK_INT >= 16) { try { Field priorityField = Notification.class.getField("priority"); priorityField.setAccessible(true); priorityField.set(notification, 1); } catch (Exception e) { PushReportUtility.oe("onReceive", e); } } PendingIntent contentIntent = PendingIntent.getActivity(context, notificationNB, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, contentTitle, tickerText, contentIntent); // NotificationNotificationManager mNotificationManager.notify(notificationNB, notification); notificationNB++; } }
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 *///from w w w .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); } }