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.gdgdevfest.android.apps.devfestbcn.service.SessionAlarmService.java
private void notifySession(final long sessionStart, final long sessionEnd, final long alarmOffset) { long currentTime; if (sessionStart < (currentTime = UIUtils.getCurrentTime(this))) return;//from w ww .j av a 2 s . c o m // Avoid repeated notifications. if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this, ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd))) { return; } final ContentResolver cr = getContentResolver(); final Uri starredBlockUri = ScheduleContract.Blocks .buildStarredSessionsUri(ScheduleContract.Blocks.generateBlockId(sessionStart, sessionEnd)); Cursor c = cr.query(starredBlockUri, SessionDetailQuery.PROJECTION, null, null, null); int starredCount = 0; ArrayList<String> starredSessionTitles = new ArrayList<String>(); ArrayList<String> starredSessionRoomIds = new ArrayList<String>(); String sessionId = null; // needed to get session track icon while (c.moveToNext()) { sessionId = c.getString(SessionDetailQuery.SESSION_ID); starredCount = c.getInt(SessionDetailQuery.NUM_STARRED_SESSIONS); starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE)); starredSessionRoomIds.add(c.getString(SessionDetailQuery.ROOM_ID)); } if (starredCount < 1) { return; } // Generates the pending intent which gets fired when the user taps on the notification. // NOTE: Use TaskStackBuilder to comply with Android's design guidelines // related to navigation from notifications. PendingIntent pi = TaskStackBuilder.create(this).addNextIntent(new Intent(this, HomeActivity.class)) .addNextIntent(new Intent(Intent.ACTION_VIEW, starredBlockUri)) .getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); final Resources res = getResources(); String contentText; int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000; if (minutesLeft < 1) { minutesLeft = 1; } if (starredCount == 1) { contentText = res.getString(R.string.session_notification_text_1, minutesLeft); } else { contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft, starredCount - 1); } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText) .setTicker(res.getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount)) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true); if (starredCount == 1) { // get the track icon to show as the notification big picture Uri tracksUri = ScheduleContract.Sessions.buildTracksDirUri(sessionId); Cursor tracksCursor = cr.query(tracksUri, SessionTrackQuery.PROJECTION, null, null, null); if (tracksCursor.moveToFirst()) { String trackName = tracksCursor.getString(SessionTrackQuery.TRACK_NAME); int trackColour = tracksCursor.getInt(SessionTrackQuery.TRACK_COLOR); Bitmap trackIcon = UIUtils.getTrackIconSync(getApplicationContext(), trackName, trackColour); if (trackIcon != null) { notifBuilder.setLargeIcon(trackIcon); } } } if (minutesLeft > 5) { notifBuilder.addAction(R.drawable.ic_alarm_holo_dark, String.format(res.getString(R.string.snooze_x_min), 5), createSnoozeIntent(sessionStart, sessionEnd, 5)); } if (starredCount == 1 && PrefUtils.isAttendeeAtVenue(this)) { notifBuilder.addAction(R.drawable.ic_map_holo_dark, res.getString(R.string.title_map), createRoomMapIntent(starredSessionRoomIds.get(0))); } NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder) .setBigContentTitle(res.getQuantityString(R.plurals.session_notification_title, starredCount, minutesLeft, starredCount)); // Adds starred sessions starting at this time block to the notification. for (int i = 0; i < starredCount; i++) { richNotification.addLine(starredSessionTitles.get(i)); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, richNotification.build()); }
From source file:copytestapp.copytestapp.GCMIntentService.java
void notificationWithColorFont(Context context, String title, String message, int icon, Class<?> activityClass, String ad_code, String eventPage, String ad_num) { Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), icon); Intent notificationIntent = new Intent(context, activityClass); notificationIntent.putExtra("adUrl", eventPage); notificationIntent.putExtra("adcodeNum", ad_code); notificationIntent.putExtra("ad_num", ad_num); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent intent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); //? ?? SmallIcon ? 24x24?..mdpi // ?? ?? - > // ? ? ?? . ( ??? X ) Notification notification = new Notification.BigTextStyle( new Notification.Builder(getApplicationContext()).setContentTitle(title) .setContentText("? ? ??? !") .setSmallIcon(icon).setLargeIcon(largeIcon).setContentIntent(intent).setAutoCancel(true) .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)) .setSummaryText("notification").bigText(message).build(); manager.notify(0, notification); }// w ww . ja v a 2 s. co m
From source file:com.mobicage.rogerthat.util.ui.UIUtils.java
public static void doNotification(Context pContext, String title, String message, int notificationId, String action, boolean withSound, boolean withVibration, boolean withLight, boolean autoCancel, int icon, int notificationNumber, Bundle extras, String tickerText, long timestamp, int priority, List<NotificationCompat.Action> actionButtons, String longNotificationText, Bitmap largeIcon, String category) {/* ww w . j a va 2s . c om*/ T.dontCare(); SharedPreferences options = PreferenceManager.getDefaultSharedPreferences(pContext); final boolean pushNotifications = options.getBoolean(MainService.PREFERENCE_PUSH_NOTIFICATIONS, false); if (!pushNotifications) { L.d("push notifications are disabled"); return; } final NotificationCompat.Builder builder = new NotificationCompat.Builder(pContext); int defaults = 0; if (withSound) { defaults |= Notification.DEFAULT_SOUND; } if (withVibration) { defaults |= Notification.DEFAULT_VIBRATE; } builder.setDefaults(defaults); if (withLight) { builder.setLights(0xff00ff00, 300, 3000); } builder.setAutoCancel(autoCancel); builder.setOngoing(!autoCancel); builder.setCategory(category); if (message != null) { builder.setSmallIcon(icon); if (largeIcon != null) { builder.setLargeIcon(largeIcon); } if (tickerText != null) { builder.setTicker(tickerText); } builder.setWhen(System.currentTimeMillis()); final Intent intent = new Intent(action, null, pContext, MainActivity.class); intent.addFlags(MainActivity.FLAG_CLEAR_STACK_SINGLE_TOP); if (extras != null) intent.putExtras(extras); intent.putExtra(NOTIFICATION_TIMESTAMP, timestamp); final PendingIntent pi = PendingIntent.getActivity(pContext, NotificationID.next(), intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pi); builder.setContentText(message); builder.setContentTitle(title); if (!TextUtils.isEmptyOrWhitespace(longNotificationText)) { builder.setStyle(new NotificationCompat.BigTextStyle().bigText(longNotificationText)); } builder.setPriority(priority); if (actionButtons != null) { for (NotificationCompat.Action actionButton : actionButtons) { builder.addAction(actionButton); } } } builder.setNumber(notificationNumber); final NotificationManager nm = (NotificationManager) pContext .getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(notificationId, builder.build()); sNotificationIDs.add(notificationId); }
From source file:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java
private void notifyMatch(long matchId) { if (!PrefUtils.shouldShowMatchReminders(this)) { return;//from ww w .j a v a 2s . c o m } final ContentResolver cr = getContentResolver(); Cursor c = cr.query(MatchContract.SeriesEntry.CONTENT_URI, MatchDetailQuery.PROJECTION, SESSION_ID_WHERE_CLAUSE, new String[] { String.valueOf(matchId) }, null); if (!c.moveToNext()) { return; } Intent baseIntent = new Intent(this, MatchActivity.class); baseIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent); Intent matchIntent = new Intent(this, MatchDetailActivity.class); matchIntent.putExtra(MatchDetailActivity.ARGS_GG_MATCH_ID, matchId); taskBuilder.addNextIntent(matchIntent); PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); final Resources res = getResources(); String contentTitle = c.getString(MatchDetailQuery.TEAM_ONE_NAME) + " vs " + c.getString(MatchDetailQuery.TEAM_TWO_NAME); String contentText; long currentTime = TimeUtils.getUTCTime(); long matchStart = c.getLong(MatchDetailQuery.DATE_TIME); int minutesLeft = (int) (matchStart - currentTime + 59000) / 60000; if (minutesLeft < 2 && minutesLeft >= 0) { minutesLeft = 1; } if (minutesLeft < 0) { contentText = "is scheduled to start now. (" + c.getString(MatchDetailQuery.TOURNAMENT_NAME) + ")"; } else { contentText = "is scheduled to start in " + minutesLeft + " min. (" + c.getString(MatchDetailQuery.TOURNAMENT_NAME) + ")"; } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this).setContentTitle(contentTitle) .setContentText(contentText).setColor(res.getColor(R.color.theme_primary)) .setTicker(contentTitle + " is about to start.") .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(NOTIFICATION_ARGB_COLOR, NOTIFICATION_LED_ON_MS, NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_DEFAULT).setAutoCancel(true); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, notifBuilder.build()); }
From source file:com.tweetlanes.android.service.BackgroundService.java
private Notification buildNotification(String message, int icon, Intent content_intent, Intent delete_intent) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setTicker(message);//w ww. j a va 2 s .c om //builder.setContentTitle(getString(R.string.new_notifications)); builder.setContentTitle("New notifications"); builder.setContentText(message); builder.setAutoCancel(true); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(icon); builder.setDeleteIntent( PendingIntent.getBroadcast(this, 0, delete_intent, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setContentIntent( PendingIntent.getActivity(this, 0, content_intent, PendingIntent.FLAG_UPDATE_CURRENT)); int defaults = 0; //if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATIONS_HAVE_SOUND, false)) { defaults |= Notification.DEFAULT_SOUND; //} //if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATIONS_HAVE_VIBRATION, false)) { defaults |= Notification.DEFAULT_VIBRATE; //} //if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATIONS_HAVE_LIGHTS, false)) { defaults |= Notification.DEFAULT_LIGHTS; //} builder.setDefaults(defaults); return builder.getNotification(); }
From source file:com.shafiq.mytwittle.service.BackgroundService.java
private Notification buildNotification(String message, int icon, Intent content_intent, Intent delete_intent) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setTicker(message);/*from w ww. ja va 2 s. c om*/ // builder.setContentTitle(getString(R.string.new_notifications)); builder.setContentTitle("New notifications"); builder.setContentText(message); builder.setAutoCancel(true); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(icon); builder.setDeleteIntent( PendingIntent.getBroadcast(this, 0, delete_intent, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setContentIntent( PendingIntent.getActivity(this, 0, content_intent, PendingIntent.FLAG_UPDATE_CURRENT)); int defaults = 0; // if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATIONS_HAVE_SOUND, // false)) { defaults |= Notification.DEFAULT_SOUND; // } // if // (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATIONS_HAVE_VIBRATION, // false)) { defaults |= Notification.DEFAULT_VIBRATE; // } // if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATIONS_HAVE_LIGHTS, // false)) { defaults |= Notification.DEFAULT_LIGHTS; // } builder.setDefaults(defaults); return builder.getNotification(); }
From source file:com.vendsy.bartsy.venue.GCMIntentService.java
/** * To generate a notification to inform the user that server has sent a message. * //from w w w.j av a 2 s. c om * @param count * @param count */ private static void generateNotification(Context context, String message, String count) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MainActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; try { int countValue = Integer.parseInt(count); notification.number = countValue; } catch (NumberFormatException e) { e.printStackTrace(); } // // Play default notification sound notification.defaults = Notification.DEFAULT_SOUND; notificationManager.notify(0, notification); }
From source file:com.userhook.UserHook.java
public static Notification handlePushMessage(Map<String, String> data) { String message = data.get("message"); String title = ""; if (data.containsKey("title") && data.get("title") != null) { title = data.get("title"); } else {//from w w w . j a v a2 s .c o m title = applicationContext.getApplicationInfo().loadLabel(applicationContext.getPackageManager()) .toString(); } Map<String, Object> payload = new HashMap<>(); if (data.containsKey("payload")) { try { JSONObject json = new JSONObject(data.get("payload")); payload = UHJsonUtils.toMap(json); // check if this is a feedback reply if (json.has("new_feedback") && json.getBoolean("new_feedback")) { UserHook.setHasNewFeedback(true); } else { UserHook.setHasNewFeedback(false); } } catch (JSONException e) { Log.e("uh", "error parsing push notification payload"); } } // message received Intent intent; if (pushMessageListener != null) { intent = pushMessageListener.onPushMessage(payload); } else { // default to opening the main activity intent = applicationContext.getPackageManager() .getLaunchIntentForPackage(applicationContext.getPackageName()); } // convert data to a try Map<String,String> since it will come in as an ArrayMap if (data instanceof ArrayMap) { HashMap<String, String> hashMap = new HashMap<>(); for (String key : data.keySet()) { hashMap.put(key, data.get(key)); } data = hashMap; } intent.putExtra(UserHook.UH_PUSH_DATA, (Serializable) data); intent.putExtra(UserHook.UH_PUSH_TRACKED, false); if (payload.size() > 0) { intent.putExtra(UserHook.UH_PUSH_PAYLOAD, data.get("payload")); } //PendingIntent.FLAG_UPDATE_CURRENT is required to pass along our Intent Extras PendingIntent pendingIntent = PendingIntent.getActivity(applicationContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); try { ApplicationInfo appInfo = applicationContext.getPackageManager() .getApplicationInfo(applicationContext.getPackageName(), PackageManager.GET_META_DATA); int pushIcon = appInfo.icon; // check for a custom push icon if (pushNotificationIcon > 0) { pushIcon = pushNotificationIcon; } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(applicationContext) .setSmallIcon(pushIcon).setContentText(message).setContentTitle(title).setAutoCancel(true) .setContentIntent(pendingIntent); // use default sound notificationBuilder.setDefaults(Notification.DEFAULT_SOUND); return notificationBuilder.build(); } catch (Exception e) { Log.e("uh", "error create push notification", e); return null; } }
From source file:com.inducesmile.androidtabwithswipe.RecoBackgroundMonitoringService.java
private void popupNotification(String msg) { Log.i("BackMonitoringService", "popupNotification()"); String currentTime = new SimpleDateFormat("HH:mm:ss", Locale.KOREA).format(new Date()); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent intent = new Intent(RecoBackgroundMonitoringService.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent content = PendingIntent.getActivity(RecoBackgroundMonitoringService.this, 0, intent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.mipmap.o2) .setTicker("") .setContentTitle(" ? ? !") .setContentText(" ? .").setContentIntent(content) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(0xffffffff, 500, 500); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); builder.setStyle(inboxStyle);/* w w w. ja v a2 s. c o m*/ nm.notify(mNotificationID, builder.build()); mNotificationID = (mNotificationID - 1) % 1000 + 9000; }
From source file:org.yaaic.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 w w . java 2 s. co m private void updateNotification(String text, String contentText, boolean vibrate, boolean sound, boolean light) { if (foreground) { 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); } } notification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_notification) .setContentTitle(getText(R.string.app_name)).setContentText(contentText) .setContentIntent(contentIntent).setWhen(System.currentTimeMillis()) .setPriority(mentions.size() > 0 ? NotificationCompat.PRIORITY_DEFAULT : NotificationCompat.PRIORITY_MIN) .setCategory(NotificationCompat.CATEGORY_PROGRESS).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); } }