List of usage examples for android.app Notification FLAG_INSISTENT
int FLAG_INSISTENT
To view the source code for android.app Notification FLAG_INSISTENT.
Click Source Link
From source file:net.networksaremadeofstring.rhybudd.Notifications.java
public static void SendPollNotification(int EventCount, List<String> EventDetails, Context context) { Intent notificationIntent = new Intent(context, ViewZenossEventsListActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("forceRefresh", true); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Intent broadcastMassAck = new Intent(); broadcastMassAck.setAction(MassAcknowledgeReceiver.BROADCAST_ACTION); PendingIntent pBroadcastMassAck = PendingIntent.getBroadcast(context, 0, broadcastMassAck, 0); /*Intent broadcastIgnore = new Intent(); broadcastIgnore.setAction(BatchIgnoreReceiver.BROADCAST_ACTION); PendingIntent pBroadcastIgnore = PendingIntent.getBroadcast(this,0,broadcastIgnore,0);*/ SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); Uri soundURI;/*w ww . j av a 2s . com*/ int Flags = -1; String Event1 = "--", Event2 = "---"; int remainingCount = 0; try { if (settings.getBoolean("notificationSound", true)) { if (settings.getString("notificationSoundChoice", "").equals("")) { soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } else { try { soundURI = Uri.parse(settings.getString("notificationSoundChoice", "")); } catch (Exception e) { soundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } } } else { soundURI = null; } } catch (Exception e) { soundURI = null; } try { if (EventDetails.size() > 1) { Event1 = EventDetails.get(0); Event2 = EventDetails.get(1); remainingCount = EventCount - 2; } else { Event1 = EventDetails.get(0); remainingCount = EventCount - 1; } } catch (Exception e) { } long[] vibrate = { 0, 100, 200, 300 }; try { AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); //Log.e("audio.getRingerMode()",Integer.toString(audio.getRingerMode())); switch (audio.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: //Do nothing to fix GitHub issue #13 //Log.e("AudioManager","Doing nothing because we are silent"); vibrate = new long[] { 0, 0 }; break; } } catch (Exception e) { e.printStackTrace(); } try { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_alert) .setContentTitle(Integer.toString(EventCount) + " new Zenoss Events!") .setContentText("Tap to start Rhybudd").setContentIntent(contentIntent).setNumber(EventCount) .setSound(soundURI).setVibrate(vibrate).setAutoCancel(true).setOngoing(false) .addAction(R.drawable.ic_action_resolve_all, "Acknowledge all Events", pBroadcastMassAck) .setPriority(Notification.PRIORITY_HIGH); Notification notif = mBuilder.build(); notif.tickerText = Integer.toString(EventCount) + " new Zenoss Events!"; if (settings.getBoolean("notificationSoundInsistent", false)) notif.flags |= Notification.FLAG_INSISTENT; NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNM.notify(NOTIFICATION_POLLED_ALERTS, notif); } catch (Exception e) { } }
From source file:nl.vanvianen.android.gcm.GCMIntentService.java
@Override @SuppressWarnings("unchecked") protected void onMessage(Context context, Intent intent) { Log.d(LCAT, "Push notification received"); boolean isTopic = false; HashMap<String, Object> data = new HashMap<String, Object>(); for (String key : intent.getExtras().keySet()) { Object value = intent.getExtras().get(key); Log.d(LCAT, "Message key: \"" + key + "\" value: \"" + value + "\""); if (key.equals("from") && value instanceof String && ((String) value).startsWith("/topics/")) { isTopic = true;/*from w ww. j a v a 2 s. c o m*/ } String eventKey = key.startsWith("data.") ? key.substring(5) : key; data.put(eventKey, intent.getExtras().get(key)); if (value instanceof String && ((String) value).startsWith("{")) { Log.d(LCAT, "Parsing JSON string..."); try { JSONObject json = new JSONObject((String) value); Iterator<String> keys = json.keys(); while (keys.hasNext()) { String jKey = keys.next(); String jValue = json.getString(jKey); Log.d(LCAT, "JSON key: \"" + jKey + "\" value: \"" + jValue + "\""); data.put(jKey, jValue); } } catch (JSONException ex) { Log.d(LCAT, "JSON error: " + ex.getMessage()); } } } /* Store data to be retrieved when resuming app as a JSON object, serialized as a String, otherwise * Ti.App.Properties.getString(GCMModule.LAST_DATA) doesn't work. */ JSONObject json = new JSONObject(data); TiApplication.getInstance().getAppProperties().setString(GCMModule.LAST_DATA, json.toString()); /* Get settings from notification object */ int smallIcon = 0; int largeIcon = 0; String sound = null; boolean vibrate = false; boolean insistent = false; String group = null; boolean localOnly = true; int priority = 0; boolean bigText = false; int notificationId = 1; Integer ledOn = null; Integer ledOff = null; String titleKey = DEFAULT_TITLE_KEY; String messageKey = DEFAULT_MESSAGE_KEY; String tickerKey = DEFAULT_TICKER_KEY; String title = null; String message = null; String ticker = null; boolean backgroundOnly = false; Map<String, Object> notificationSettings = new Gson().fromJson( TiApplication.getInstance().getAppProperties().getString(GCMModule.NOTIFICATION_SETTINGS, null), Map.class); if (notificationSettings != null) { if (notificationSettings.get("smallIcon") instanceof String) { smallIcon = getResource("drawable", (String) notificationSettings.get("smallIcon")); } else { Log.e(LCAT, "Invalid setting smallIcon, should be String"); } if (notificationSettings.get("largeIcon") instanceof String) { largeIcon = getResource("drawable", (String) notificationSettings.get("largeIcon")); } else { Log.e(LCAT, "Invalid setting largeIcon, should be String"); } if (notificationSettings.get("sound") != null) { if (notificationSettings.get("sound") instanceof String) { sound = (String) notificationSettings.get("sound"); } else { Log.e(LCAT, "Invalid setting sound, should be String"); } } if (notificationSettings.get("vibrate") != null) { if (notificationSettings.get("vibrate") instanceof Boolean) { vibrate = (Boolean) notificationSettings.get("vibrate"); } else { Log.e(LCAT, "Invalid setting vibrate, should be Boolean"); } } if (notificationSettings.get("insistent") != null) { if (notificationSettings.get("insistent") instanceof Boolean) { insistent = (Boolean) notificationSettings.get("insistent"); } else { Log.e(LCAT, "Invalid setting insistent, should be Boolean"); } } if (notificationSettings.get("group") != null) { if (notificationSettings.get("group") instanceof String) { group = (String) notificationSettings.get("group"); } else { Log.e(LCAT, "Invalid setting group, should be String"); } } if (notificationSettings.get("localOnly") != null) { if (notificationSettings.get("localOnly") instanceof Boolean) { localOnly = (Boolean) notificationSettings.get("localOnly"); } else { Log.e(LCAT, "Invalid setting localOnly, should be Boolean"); } } if (notificationSettings.get("priority") != null) { if (notificationSettings.get("priority") instanceof Integer) { priority = (Integer) notificationSettings.get("priority"); } else if (notificationSettings.get("priority") instanceof Double) { priority = ((Double) notificationSettings.get("priority")).intValue(); } else { Log.e(LCAT, "Invalid setting priority, should be an integer, between PRIORITY_MIN (" + NotificationCompat.PRIORITY_MIN + ") and PRIORITY_MAX (" + NotificationCompat.PRIORITY_MAX + ")"); } } if (notificationSettings.get("bigText") != null) { if (notificationSettings.get("bigText") instanceof Boolean) { bigText = (Boolean) notificationSettings.get("bigText"); } else { Log.e(LCAT, "Invalid setting bigText, should be Boolean"); } } if (notificationSettings.get("titleKey") != null) { if (notificationSettings.get("titleKey") instanceof String) { titleKey = (String) notificationSettings.get("titleKey"); } else { Log.e(LCAT, "Invalid setting titleKey, should be String"); } } if (notificationSettings.get("messageKey") != null) { if (notificationSettings.get("messageKey") instanceof String) { messageKey = (String) notificationSettings.get("messageKey"); } else { Log.e(LCAT, "Invalid setting messageKey, should be String"); } } if (notificationSettings.get("tickerKey") != null) { if (notificationSettings.get("tickerKey") instanceof String) { tickerKey = (String) notificationSettings.get("tickerKey"); } else { Log.e(LCAT, "Invalid setting tickerKey, should be String"); } } if (notificationSettings.get("title") != null) { if (notificationSettings.get("title") instanceof String) { title = (String) notificationSettings.get("title"); } else { Log.e(LCAT, "Invalid setting title, should be String"); } } if (notificationSettings.get("message") != null) { if (notificationSettings.get("message") instanceof String) { message = (String) notificationSettings.get("message"); } else { Log.e(LCAT, "Invalid setting message, should be String"); } } if (notificationSettings.get("ticker") != null) { if (notificationSettings.get("ticker") instanceof String) { ticker = (String) notificationSettings.get("ticker"); } else { Log.e(LCAT, "Invalid setting ticker, should be String"); } } if (notificationSettings.get("ledOn") != null) { if (notificationSettings.get("ledOn") instanceof Integer) { ledOn = (Integer) notificationSettings.get("ledOn"); if (ledOn < 0) { Log.e(LCAT, "Invalid setting ledOn, should be positive"); ledOn = null; } } else { Log.e(LCAT, "Invalid setting ledOn, should be Integer"); } } if (notificationSettings.get("ledOff") != null) { if (notificationSettings.get("ledOff") instanceof Integer) { ledOff = (Integer) notificationSettings.get("ledOff"); if (ledOff < 0) { Log.e(LCAT, "Invalid setting ledOff, should be positive"); ledOff = null; } } else { Log.e(LCAT, "Invalid setting ledOff, should be Integer"); } } if (notificationSettings.get("backgroundOnly") != null) { if (notificationSettings.get("backgroundOnly") instanceof Boolean) { backgroundOnly = (Boolean) notificationSettings.get("backgroundOnly"); } else { Log.e(LCAT, "Invalid setting backgroundOnly, should be Boolean"); } } if (notificationSettings.get("notificationId") != null) { if (notificationSettings.get("notificationId") instanceof Integer) { notificationId = (Integer) notificationSettings.get("notificationId"); } else { Log.e(LCAT, "Invalid setting notificationId, should be Integer"); } } } else { Log.d(LCAT, "No notification settings found"); } /* If icon not found, default to appicon */ if (smallIcon == 0) { smallIcon = getResource("drawable", "appicon"); } /* If large icon not found, default to icon */ if (largeIcon == 0) { largeIcon = smallIcon; } /* Create intent to (re)start the app's root activity */ String pkg = TiApplication.getInstance().getApplicationContext().getPackageName(); Intent launcherIntent = TiApplication.getInstance().getApplicationContext().getPackageManager() .getLaunchIntentForPackage(pkg); launcherIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER); /* Grab notification content from data according to provided keys if not already set */ if (title == null && titleKey != null) { title = (String) data.get(titleKey); } if (message == null && messageKey != null) { message = (String) data.get(messageKey); } if (ticker == null && tickerKey != null) { ticker = (String) data.get(tickerKey); } Log.i(LCAT, "Title: " + title); Log.i(LCAT, "Message: " + message); Log.i(LCAT, "Ticker: " + ticker); /* Check for app state */ if (GCMModule.getInstance() != null) { /* Send data to app */ if (isTopic) { GCMModule.getInstance().sendTopicMessage(data); } else { GCMModule.getInstance().sendMessage(data); } /* Do not create notification if backgroundOnly and app is in foreground */ if (backgroundOnly && GCMModule.getInstance().isInForeground()) { Log.d(LCAT, "Notification received in foreground, no need for notification."); return; } } if (message == null) { Log.d(LCAT, "Message received but no 'message' specified in push notification payload, so will make this silent"); } else { Log.d(LCAT, "Creating notification..."); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), largeIcon); if (bitmap == null) { Log.d(LCAT, "No large icon found"); } NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setTicker(ticker) .setContentIntent( PendingIntent.getActivity(this, 0, launcherIntent, PendingIntent.FLAG_ONE_SHOT)) .setSmallIcon(smallIcon).setLargeIcon(bitmap); /* Name of group to group similar notifications together, can also be set in the push notification payload */ if (data.get("group") != null) { group = (String) data.get("group"); } if (group != null) { builder.setGroup(group); } Log.i(LCAT, "Group: " + group); /* Whether notification should be for this device only or bridged to other devices, can also be set in the push notification payload */ if (data.get("localOnly") != null) { localOnly = Boolean.valueOf((String) data.get("localOnly")); } builder.setLocalOnly(localOnly); Log.i(LCAT, "LocalOnly: " + localOnly); /* Specify notification priority, can also be set in the push notification payload */ if (data.get("priority") != null) { priority = Integer.parseInt((String) data.get("priority")); } if (priority >= NotificationCompat.PRIORITY_MIN && priority <= NotificationCompat.PRIORITY_MAX) { builder.setPriority(priority); Log.i(LCAT, "Priority: " + priority); } else { Log.e(LCAT, "Ignored invalid priority " + priority); } /* Specify whether bigtext should be used, can also be set in the push notification payload */ if (data.get("bigText") != null) { bigText = Boolean.valueOf((String) data.get("bigText")); } if (bigText) { builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); } Log.i(LCAT, "bigText: " + bigText); Notification notification = builder.build(); /* Sound, can also be set in the push notification payload */ if (data.get("sound") != null) { Log.d(LCAT, "Sound specified in notification"); sound = (String) data.get("sound"); } if ("default".equals(sound)) { Log.i(LCAT, "Sound: default sound"); notification.defaults |= Notification.DEFAULT_SOUND; } else if (sound != null) { Log.i(LCAT, "Sound " + sound); notification.sound = Uri.parse("android.resource://" + pkg + "/" + getResource("raw", sound)); } /* Vibrate, can also be set in the push notification payload */ if (data.get("vibrate") != null) { vibrate = Boolean.valueOf((String) data.get("vibrate")); } if (vibrate) { notification.defaults |= Notification.DEFAULT_VIBRATE; } Log.i(LCAT, "Vibrate: " + vibrate); /* Insistent, can also be set in the push notification payload */ if ("true".equals(data.get("insistent"))) { insistent = true; } if (insistent) { notification.flags |= Notification.FLAG_INSISTENT; } Log.i(LCAT, "Insistent: " + insistent); /* notificationId, set in push payload to specify multiple notifications should be shown. If not specified, subsequent notifications "override / overwrite" the older ones */ if (data.get("notificationId") != null) { if (data.get("notificationId") instanceof Integer) { notificationId = (Integer) data.get("notificationId"); } else if (data.get("notificationId") instanceof String) { try { notificationId = Integer.parseInt((String) data.get("notificationId")); } catch (NumberFormatException ex) { Log.e(LCAT, "Invalid setting notificationId, should be Integer"); } } else { Log.e(LCAT, "Invalid setting notificationId, should be Integer"); } } Log.i(LCAT, "Notification ID: " + notificationId); /* Specify LED flashing */ if (ledOn != null || ledOff != null) { notification.flags |= Notification.FLAG_SHOW_LIGHTS; if (ledOn != null) { notification.ledOnMS = ledOn; } if (ledOff != null) { notification.ledOffMS = ledOff; } } else { notification.defaults |= Notification.DEFAULT_LIGHTS; } notification.flags |= Notification.FLAG_AUTO_CANCEL; ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(notificationId, notification); } }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
private void SendNotification(String tickerText, String expandedText) { NotificationManager notificationManager = (NotificationManager) contextWrapper .getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.ateamlogo; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.flags |= (Notification.FLAG_INSISTENT | Notification.FLAG_AUTO_CANCEL); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_LIGHTS; Context context = contextWrapper.getApplicationContext(); // Intent to launch an activity when the extended text is clicked Intent intent2 = new Intent(contextWrapper, SUTAgentAndroid.class); PendingIntent launchIntent = PendingIntent.getActivity(context, 0, intent2, 0); notification.setLatestEventInfo(context, tickerText, expandedText, launchIntent); notificationManager.notify(1959, notification); }
From source file:org.thecongers.mtpms.MainActivity.java
private void Notify(String notificationMessage) { notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent intent = new Intent(this, MainActivity.class); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); String alertURI = sharedPrefs.getString("prefsound", "content://settings/system/notification_sound"); Uri soundURI = Uri.parse(alertURI);/*w w w . j av a 2 s . com*/ // Build notification NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(getResources().getString(R.string.app_shortName)) .setContentText(notificationMessage).setSmallIcon(R.drawable.notification_icon).setAutoCancel(false) .setOnlyAlertOnce(true).setPriority(Notification.PRIORITY_MAX).setContentIntent(pendingIntent); // Check for LED enabled if (sharedPrefs.getBoolean("prefNotificationLED", true)) { builder.setLights(android.graphics.Color.RED, 1500, 1500); } // Check for sound enabled if (sharedPrefs.getBoolean("prefNotificationSound", true)) { builder.setSound(soundURI); } Notification notification = builder.build(); // Check for vibration enabled if (sharedPrefs.getBoolean("prefNotificationVibrate", false)) { notification.defaults |= Notification.DEFAULT_VIBRATE; } // Make alert repeat until read notification.flags |= Notification.FLAG_INSISTENT; // Send notification notificationManager.notify(0, notification); }
From source file:org.restcomm.android.sdk.RCDevice.java
void onNotificationCall(RCConnection connection, HashMap<String, String> customHeaders) { String peerSipUri = connection.getPeer().replaceAll("^<", "").replaceAll(">$", ""); String peerUsername = peerSipUri.replaceAll(".*?sip:", "").replaceAll("@.*$", ""); String text;/*from w w w .j a v a 2s. co m*/ if (connection.getRemoteMediaType() == RCConnection.ConnectionMediaType.AUDIO_VIDEO) { text = "Incoming video call"; } else { text = "Incoming audio call"; } // Intent to open the call activity (for when tapping on the general notification area) Intent serviceIntentDefault = new Intent(ACTION_NOTIFICATION_CALL_DEFAULT, null, getApplicationContext(), RCDevice.class); serviceIntentDefault.putExtra(RCDevice.EXTRA_DID, peerSipUri); serviceIntentDefault.putExtra(RCDevice.EXTRA_VIDEO_ENABLED, (connection.getRemoteMediaType() == RCConnection.ConnectionMediaType.AUDIO_VIDEO)); if (customHeaders != null) { serviceIntentDefault.putExtra(RCDevice.EXTRA_CUSTOM_HEADERS, customHeaders); } // Intent to directly answer the call as video (using separate actions instead of EXTRAs, cause with EXTRAs the intents aren't actually differentiated: see PendingIntent reference documentation) Intent serviceIntentVideo = new Intent(ACTION_NOTIFICATION_CALL_ACCEPT_VIDEO, null, getApplicationContext(), RCDevice.class); serviceIntentVideo.putExtras(serviceIntentDefault); // Intent to directly answer the call as audio Intent serviceIntentAudio = new Intent(ACTION_NOTIFICATION_CALL_ACCEPT_AUDIO, null, getApplicationContext(), RCDevice.class); serviceIntentAudio.putExtras(serviceIntentDefault); // Intent to decline the call without opening the App Activity Intent serviceIntentDecline = new Intent(ACTION_NOTIFICATION_CALL_DECLINE, null, getApplicationContext(), RCDevice.class); serviceIntentDecline.putExtras(serviceIntentDefault); // Intent for when the user deletes notification Intent serviceIntentDelete = new Intent(ACTION_NOTIFICATION_CALL_DELETE, null, getApplicationContext(), RCDevice.class); serviceIntentDelete.putExtras(serviceIntentDefault); NotificationCompat.Builder builder = getNotificationBuilder(true); builder.setSmallIcon(R.drawable.ic_call_24dp).setContentTitle(peerUsername).setContentText(text) // Need this to show up as Heads-up Notification .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true) // cancel notification when user acts on it (Important: only applies to default notification area, not additional actions) .setVibrate(notificationVibrationPattern).setVisibility(Notification.VISIBILITY_PUBLIC) .setLights(notificationColor, notificationColorPattern[0], notificationColorPattern[1]); if (audioManager != null) builder = builder.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + audioManager.getResourceIdForKey(ParameterKeys.RESOURCE_SOUND_RINGING))); if (callIntent != null) { builder = builder .addAction(R.drawable.ic_videocam_24dp, "Video", PendingIntent.getService(getApplicationContext(), 0, serviceIntentVideo, PendingIntent.FLAG_UPDATE_CURRENT)) .addAction(R.drawable.ic_call_24dp, "Audio", PendingIntent.getService(getApplicationContext(), 0, serviceIntentAudio, PendingIntent.FLAG_UPDATE_CURRENT)) .addAction(R.drawable.ic_call_end_24dp, "Hang Up", PendingIntent.getService(getApplicationContext(), 0, serviceIntentDecline, PendingIntent.FLAG_UPDATE_CURRENT)) .setContentIntent(PendingIntent.getService(getApplicationContext(), 0, serviceIntentDefault, PendingIntent.FLAG_UPDATE_CURRENT)) .setDeleteIntent(PendingIntent.getService(getApplicationContext(), 0, serviceIntentDelete, PendingIntent.FLAG_UPDATE_CURRENT)); } else { //we dont want to show the notification to primary channel builder = builder.setContentIntent(PendingIntent.getService(getApplicationContext(), 0, serviceIntentDefault, PendingIntent.FLAG_UPDATE_CURRENT)); } Notification notification = builder.build(); // Add FLAG_INSISTENT so that the notification rings repeatedly (FLAG_INSISTENT is not exposed via builder, let's add manually) notification.flags = notification.flags | Notification.FLAG_INSISTENT; boolean notificationIdExists = true; Integer activeNotificationId = callNotifications.get(peerUsername); if (activeNotificationId == null) { activeNotificationId = notificationId; notificationIdExists = false; } //show to the user notification and start foreground startForeground(notificationId, notification); if (!notificationIdExists) { // We used a new notification id, so we need to update call notifications callNotifications.put(peerUsername, notificationId); notificationId++; } activeCallNotification = true; }