List of usage examples for android.app Notification DEFAULT_ALL
int DEFAULT_ALL
To view the source code for android.app Notification DEFAULT_ALL.
Click Source Link
From source file:com.ushahidi.android.app.UshahidiService.java
private void showNotification(String tickerText) { // This is what should be launched if the user selects our notification. Intent baseIntent = new Intent(this, IncidentsTab.class); baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, baseIntent, 0); // choose the ticker text newUshahidiReportNotification = new Notification(R.drawable.favicon, tickerText, System.currentTimeMillis()); newUshahidiReportNotification.contentIntent = contentIntent; newUshahidiReportNotification.flags = Notification.FLAG_AUTO_CANCEL; newUshahidiReportNotification.defaults = Notification.DEFAULT_ALL; newUshahidiReportNotification.setLatestEventInfo(this, TAG, tickerText, contentIntent); if (UshahidiPref.ringtone) { // set the ringer Uri ringURI = Uri.fromFile(new File("/system/media/audio/ringtones/ringer.mp3")); newUshahidiReportNotification.sound = ringURI; }/*from www .j a v a2 s . c om*/ if (UshahidiPref.vibrate) { double vibrateLength = 100 * Math.exp(0.53 * 20); long[] vibrate = new long[] { 100, 100, (long) vibrateLength }; newUshahidiReportNotification.vibrate = vibrate; if (UshahidiPref.flashLed) { int color = Color.BLUE; newUshahidiReportNotification.ledARGB = color; } newUshahidiReportNotification.ledOffMS = (int) vibrateLength; newUshahidiReportNotification.ledOnMS = (int) vibrateLength; newUshahidiReportNotification.flags = newUshahidiReportNotification.flags | Notification.FLAG_SHOW_LIGHTS; } mNotificationManager.notify(UshahidiPref.NOTIFICATION_ID, newUshahidiReportNotification); }
From source file:com.commonsware.android.webserver.secure.WebServerService.java
private void foregroundify() { NotificationCompat.Builder b = new NotificationCompat.Builder(this); Intent iActivity = new Intent(this, MainActivity.class); PendingIntent piActivity = PendingIntent.getActivity(this, 0, iActivity, 0); Intent iReceiver = new Intent(this, StopReceiver.class); PendingIntent piReceiver = PendingIntent.getBroadcast(this, 0, iReceiver, 0); b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setContentTitle(getString(R.string.app_name)) .setContentIntent(piActivity).setSmallIcon(R.mipmap.ic_launcher) .setTicker(getString(R.string.app_name)) .addAction(R.drawable.ic_stop_white_24dp, getString(R.string.notify_stop), piReceiver); startForeground(1337, b.build());/*from ww w .j av a2 s . co m*/ }
From source file:org.sigimera.app.android.GCMIntentService.java
@Override protected final void onMessage(final Context context, final Intent message) { final Intent msg = message; this.mainThreadHandler.post(new Runnable() { public void run() { ApplicationController controller = ApplicationController.getInstance(); controller.init(getApplicationContext(), getSharedPreferences(Constants.PREFS_NAME, 0), null); String authToken = controller.getSharedPreferences().getString("auth_token", null); final String type = msg.getStringExtra("sig_message_type"); if (type.equalsIgnoreCase("NEW_CRISIS")) { /**/* w w w. j a v a 2 s. com*/ * XXX: Blocks UI: Shift this code into a separate * background thread */ Crisis crisis = PersistanceController.getInstance().getCrisis(authToken, msg.getStringExtra("crisis_id")); StringBuffer message = new StringBuffer(); if (crisis != null) { message.append(crisis.getID()); message.append(" was stored successfully!"); } else { message.append("Not able to get crisis!"); } Toast.makeText(getApplicationContext(), message.toString(), Toast.LENGTH_LONG).show(); } else if (type.equalsIgnoreCase("PING")) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); Intent notificationIntent = new Intent(); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setContentTitle("Sigimera PING!") .setContentText("Congratulations, push notifcation received!") .setSmallIcon(R.drawable.sigimera_logo).setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL).setContentIntent(contentIntent).build(); mNotificationManager.notify(Constants.PING_ID, notification); } else if (type.equalsIgnoreCase("CRISIS_ALERT")) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); /** * XXX: Not working with random ID. That makes always the * latest notification clickable, but not the older ones. */ int notificationID = new Random().nextInt(); Intent notificationIntent = new Intent(getApplicationContext(), CrisisAlertActivity.class); notificationIntent.putExtra("notification_id", notificationID); notificationIntent.putExtra("crisis_id", msg.getStringExtra("crisis_id")); notificationIntent.putExtra("crisis_type", msg.getStringExtra("crisis_type")); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new NotificationCompat.Builder(getApplicationContext()) .setContentTitle("CRISIS ALERT!") .setContentText("Crisis found: " + msg.getStringExtra("crisis_id")) .setSmallIcon(R.drawable.alert_red).setOngoing(true).setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL).setContentIntent(contentIntent).build(); mNotificationManager.notify(notificationID, notification); } else if (type.equalsIgnoreCase("SHARED_CRISIS")) { Intent intent = new Intent(GCMIntentService.this, CrisisActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(Constants.CRISIS_ID, msg.getStringExtra("crisis_id")); intent.putExtra(Constants.WINDOW_TYPE, Constants.WINDOW_TYPE_SHARED_CRISIS); startActivity(intent); } else if (type.equalsIgnoreCase("UNREGISTER_DEVICE")) { GCMRegistrar.unregister(ApplicationController.getInstance().getApplicationContext()); } else if (type.equalsIgnoreCase("REFRESH")) { LocationUpdaterHttpHelper locUpdater = new LocationUpdaterHttpHelper(); Location loc = LocationController.getInstance().getLastKnownLocation(); if (loc != null) { String latitude = loc.getLatitude() + ""; String longitude = loc.getLongitude() + ""; if (authToken != null) { locUpdater.execute(authToken, latitude, longitude); } } else { // TODO: Notify the user that the update location flow // has not worked. } } } }); }
From source file:com.adkdevelopment.earthquakesurvival.ui.geofence.GeofenceService.java
/** * Sends a notification to the phone//from ww w. ja v a2s. c om * @param notificationDetails String with details to show in the notification */ private void sendNotification(List<String> notificationDetails) { Context context = getBaseContext(); // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(context, DetailActivity.class); notificationIntent.putStringArrayListExtra(Feature.GEOFENCE, (ArrayList<String>) notificationDetails); // Construct a task stack. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Add the main Activity to the task stack as the parent. stackBuilder.addParentStack(PagerActivity.class); // Push the content Intent onto the stack. stackBuilder.addNextIntent(notificationIntent); // Get a PendingIntent containing the entire back stack. PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); Bitmap largeIcon = null; try { largeIcon = Picasso.with(context).load(R.mipmap.ic_launcher).get(); } catch (IOException e) { Log.e(TAG, "e:" + e); } // Define the notification settings. builder.setAutoCancel(true).setSmallIcon(R.mipmap.ic_launcher).setDefaults(Notification.DEFAULT_ALL) .setLargeIcon(largeIcon).setColor(Color.RED).setTicker(getString(R.string.geofence_notification)) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.geofence_notification_text)) .setContentIntent(notificationPendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText( notificationDetails.get(0) + "\n" + getString(R.string.geofence_notification_text))) .setGroup(EarthquakeObject.NOTIFICATION_GROUP); // Get an instance of the Notification manager NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context); // Issue the notification mNotificationManager.notify(EarthquakeObject.NOTIFICATION_ID_1, builder.build()); }
From source file:eu.operando.operandoapp.util.NotificationUtil.java
public void displayExfiltratedNotification(Context context, String applicationInfo, Set<RequestFilterUtil.FilterType> exfiltrated, int mainNotificationId) { try {//from ww w. j av a2s . c o m StringBuilder sb = new StringBuilder(); for (RequestFilterUtil.FilterType f : exfiltrated) { sb.append(f + ", "); } sb.delete(sb.length() - 2, sb.length() - 1); RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.proxy_notification_small); smallContentView.setImageViewResource(R.id.image, R.drawable.logo_bevel); smallContentView.setTextViewText(R.id.titleTxtView, "Personal Information"); smallContentView.setTextViewText(R.id.subtitleTxtView, "Expand for more info"); RemoteViews bigContentView = new RemoteViews(context.getPackageName(), R.layout.proxy_notification_large); bigContentView.setImageViewResource(R.id.image, R.drawable.logo_bevel); bigContentView.setTextViewText(R.id.titleTxtView, "Personal Information"); bigContentView.setTextViewText(R.id.subtitleTxtView, applicationInfo.replaceAll("\\s\\(.*?\\)", "") + " requires access to " + sb); bigContentView.setTextViewText(R.id.allowBtn, "Allow"); bigContentView.setTextViewText(R.id.blockBtn, "Block"); //get exfiltrated info to string array String[] exfiltrated_array = new String[exfiltrated.size()]; int i = 0; for (RequestFilterUtil.FilterType filter_type : exfiltrated) { exfiltrated_array[i] = filter_type.name(); i++; } //set listeners for notification buttons Intent allowIntent = new Intent(context, NotificationActivityReceiver.class); allowIntent.setAction("allow"); Bundle allowBundle = new Bundle(); allowBundle.putString("appInfo", applicationInfo); allowBundle.putInt("notificationId", mainNotificationId); allowBundle.putStringArray("exfiltrated", exfiltrated_array); allowIntent.putExtras(allowBundle); PendingIntent pendingAllowIntent = PendingIntent.getBroadcast(context, mainNotificationId + 1, allowIntent, PendingIntent.FLAG_UPDATE_CURRENT); bigContentView.setOnClickPendingIntent(R.id.allowBtn, pendingAllowIntent); Intent blockIntent = new Intent(context, NotificationActivityReceiver.class); blockIntent.setAction("block"); Bundle blockBundle = new Bundle(); blockBundle.putString("appInfo", applicationInfo); blockBundle.putInt("notificationId", mainNotificationId); blockBundle.putStringArray("exfiltrated", exfiltrated_array); blockIntent.putExtras(blockBundle); PendingIntent pendingBlockIntent = PendingIntent.getBroadcast(context, mainNotificationId + 2, blockIntent, PendingIntent.FLAG_UPDATE_CURRENT); bigContentView.setOnClickPendingIntent(R.id.blockBtn, pendingBlockIntent); Notification.Builder mBuilder = new Notification.Builder(context).setSmallIcon(R.drawable.logo_bevel) .setContent(smallContentView); Notification proxyNotification = mBuilder.build(); proxyNotification.defaults |= Notification.DEFAULT_ALL; proxyNotification.bigContentView = bigContentView; NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(mainNotificationId, proxyNotification); DatabaseHelper db = new DatabaseHelper(context); db.addPendingNotification(new PendingNotification(applicationInfo, TextUtils.join(", ", exfiltrated_array), mainNotificationId)); } catch (Exception e) { Log.d("ERROR", e.getMessage()); } }
From source file:com.dotcom.jamaat.fcm.GCMListenerService.java
/** * Create and show a simple notification containing the received GCM * message./*from w ww . j av a 2 s . c o m*/ * <p/> * <p/> * GCM message received. */ public void displayNotificationInNotificationBar(Map data) { try { String messageData = data.get("message").toString(); int notifyID = Constants.NOTIFICATION_ID; //String eData = data.getString("extra_data"); String message = ""; if (!TextUtils.isEmpty(messageData)) { JSONObject extra_data = new JSONObject(messageData); message = extra_data.optString("message"); } // This intent is fired when notification is clicked NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Intent intent; String messages = SharedPreferencesManager.getStringPreference("notificationMessage", null); if (messages != null && !messages.isEmpty()) { messages = message + ";" + messages; SharedPreferencesManager.setPreference("notificationMessage", messages); intent = new Intent(this, NotificationActivity.class); } else { SharedPreferencesManager.setPreference("notificationMessage", message); intent = new Intent(this, NotificationActivity.class); } intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); String currentMessages = SharedPreferencesManager.getStringPreference("notificationMessage", null); String[] messagesArray = currentMessages.split(";"); int count = messagesArray.length; if (messagesArray.length == 0) { notificationManager.cancel(notifyID); return; } final String GROUP_KEY_MESSAGES = "group_key_messages"; // Group notification that will be visible on the phone NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); mBuilder.setTicker(getString(R.string.app_name)).setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.app_name)).setSound(defaultSoundUri).setAutoCancel(true) .setOnlyAlertOnce(false).setPriority(Notification.PRIORITY_MAX) // .setOngoing(true) // .setWhen( System.currentTimeMillis() ) .setContentIntent(pendingIntent).setSmallIcon(R.mipmap.ic_launcher).setGroup(GROUP_KEY_MESSAGES) .setGroupSummary(true).build(); NotificationCompat.Style style; if (count > 1) { NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); style = inboxStyle; mBuilder.setContentTitle(getString(R.string.app_name)); for (String r : messagesArray) { inboxStyle.addLine(r); } mBuilder.setContentText(count + " new messages"); inboxStyle.setBigContentTitle(getString(R.string.app_name)); inboxStyle.setSummaryText(count + " new messages"); } else { NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); style = bigTextStyle; // bigTextStyle.setBigContentTitle(messagesArray[0].substring(0, 10).concat(" ...")); bigTextStyle.setBigContentTitle(getString(R.string.app_name)); mBuilder.setContentText(message); bigTextStyle.bigText(message); // bigTextStyle.setSummaryText(count + " new event"); } mBuilder.setStyle(style); NotificationManagerCompat notificationManager1 = NotificationManagerCompat.from(this); notificationManager1.notify(notifyID, mBuilder.build()); } catch (Exception ex) { } }
From source file:alaindc.memenguage.RandomIntentService.java
private void sendNotification(long id_word) { String title = "Memenguage"; String description = "Do you remember?"; // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(getApplicationContext(), GuessActivity.class); notificationIntent.setAction(Constants.ACTION_GUESS_ACTIVITY); notificationIntent.putExtra(Constants.EXTRA_GUESS_IDWORD, id_word); // Construct a task stack. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Add the main Activity to the task stack as the parent. stackBuilder.addParentStack(MainActivity.class); // Push the content Intent onto the stack. stackBuilder.addNextIntentWithParentStack(notificationIntent); // Get a PendingIntent containing the entire back stack. PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // Define the notification settings. builder.setSmallIcon(R.drawable.icon) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo)).setColor(Color.RED) .setContentTitle(title).setContentText(description).setDefaults(Notification.DEFAULT_ALL) .setContentIntent(notificationPendingIntent); try {/*from ww w . j a v a 2 s .c om*/ String urisound = PreferenceManager.getDefaultSharedPreferences(this).getString("sound_notifications", ""); builder.setSound(Uri.parse(urisound)); } catch (Exception e) { Log.d("RandomIntentService", "Uri sound notification empty or wrong"); } try { Boolean vibrate = PreferenceManager.getDefaultSharedPreferences(this) .getBoolean("vibrate_notifications", false); if (vibrate) builder.setVibrate(new long[] { 1000, 1000 }); } catch (Exception e) { Log.d("RandomIntentService", "Vibrate notification wrong"); } builder.setDefaults(0); // Dismiss notification once the user touches it. builder.setAutoCancel(true); // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(Constants.ID_NOTIFICATION_RANDOM_WORD, builder.build()); }
From source file:conversandroid.cookingnotifications.MainActivity.java
/** * Notification with an action (opens recipes web page) *///from w w w . j a v a 2 s . c o m private void showActionNotification() { int notificationId = 2; // Build an intent for an action to open a url Intent urlIntent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse("http://www.reciperoulette.tv/"); urlIntent.setData(uri); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, urlIntent, 0); //Building notification layout NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.cook).setContentTitle("Cooking tips").setContentText("New recipe available") .setDefaults(Notification.DEFAULT_ALL) //Beware that without some default behaviours //the notification may not show up in the wearable .setAutoCancel(true).setContentIntent(pendingIntent) .addAction(R.mipmap.cook, "Check recipe", pendingIntent); //Creating an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); // Building the notification and issuing it with the notification manager notificationManager.notify(notificationId, notificationBuilder.build()); }
From source file:com.qiscus.sdk.service.QiscusPusherService.java
private void showPushNotification(QiscusComment comment) { QiscusCacheManager.getInstance().addMessageNotifItem(comment.getMessage(), comment.getRoomId()); Intent openIntent = new Intent("com.qiscus.OPEN_COMMENT_PN"); openIntent.putExtra("data", comment); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, openIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setContentTitle(Qiscus.getChatConfig().getNotificationTitleHandler().getTitle(comment)) .setContentIntent(pendingIntent) .setContentText(isAttachment(comment.getMessage()) ? fileMessage : comment.getMessage()) .setTicker(isAttachment(comment.getMessage()) ? fileMessage : comment.getMessage()) .setSmallIcon(Qiscus.getChatConfig().getNotificationSmallIcon()) .setLargeIcon(BitmapFactory.decodeResource(getResources(), Qiscus.getChatConfig().getNotificationBigIcon())) .setGroupSummary(true).setGroup("CHAT_NOTIF_" + comment.getRoomId()).setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); List<String> notifItems = QiscusCacheManager.getInstance().getMessageNotifItems(comment.getRoomId()); for (String message : notifItems) { if (isAttachment(message)) { inboxStyle.addLine(fileMessage); } else {/*from w ww . j a v a 2 s . co m*/ inboxStyle.addLine(message); } } inboxStyle.setSummaryText(notifItems.size() + " new message"); notificationBuilder.setStyle(inboxStyle); NotificationManagerCompat.from(this).notify(comment.getRoomId(), notificationBuilder.build()); }
From source file:com.snot.whereareyou.GcmIntentService.java
private void sendNotification(String title, Uri uri) { Intent i = new Intent(Intent.ACTION_VIEW, uri); PendingIntent pIntent = PendingIntent.getActivity(this, 0, i, 0); // Build notification Notification notification = new NotificationCompat.Builder(this).setContentTitle(title).setContentText("") .setSmallIcon(R.drawable.ic_launcher).setContentIntent(pIntent).build(); notification.defaults |= Notification.DEFAULT_ALL; // Hide the notification after its selected notification.flags |= Notification.FLAG_AUTO_CANCEL; // Add notification to NotificationManager NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notification); }