List of usage examples for android.app Notification PRIORITY_HIGH
int PRIORITY_HIGH
To view the source code for android.app Notification PRIORITY_HIGH.
Click Source Link
From source file:com.mattprecious.locnotifier.LocationService.java
@TargetApi(16) private void updateRunningNotification(float distance) { String message;//from w ww.j a v a2 s .c om if (distance == -1) { message = getString(R.string.notification_awaiting); } else { boolean imperial = preferences.getBoolean("imperial", false); int distanceStrId = imperial ? R.string.distance_feet : R.string.distance_metres; long displayDistance = imperial ? Math.round(distance * 3.2808399) : Math.round(distance); message = getString(R.string.notification_tracking, getString(distanceStrId, displayDistance)); } String title = getString(R.string.app_name); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, LocationNotifier.class), 0); if (runningNotification == null) { runningNotification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.notification_running) .setContentTitle(title).setContentText(message).setContentIntent(contentIntent) .setOnlyAlertOnce(true).getNotification(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (preferences.getString("notification_priority", "low").equals("low")) { runningNotification.priority = Notification.PRIORITY_MIN; } else { runningNotification.priority = Notification.PRIORITY_HIGH; } } startForeground(R.string.app_name, runningNotification); } else { // TODO: Figure out how to do this without using the deprecated setLatestEventInfo runningNotification.setLatestEventInfo(this, title, message, contentIntent); notificationManager.notify(R.string.app_name, runningNotification); } }
From source file:us.alerted.alerted.LocationService.java
protected static void postNotification(Intent intentAction, Context context) { List<Alert> alerts = Alert.find(Alert.class, null, null, null, "effective DESC", "1"); Map<String, Integer> categoryLookup = new HashMap<>(); {/*from w w w. j a v a2 s . c o m*/ categoryLookup.put("Geo", R.drawable.geo); categoryLookup.put("Met", R.drawable.met); categoryLookup.put("Safety", R.drawable.safety); categoryLookup.put("Security", R.drawable.security); categoryLookup.put("Rescue", R.drawable.rescue); categoryLookup.put("Fire", R.drawable.fire); categoryLookup.put("Health", R.drawable.health); categoryLookup.put("Env", R.drawable.env); categoryLookup.put("Transport", R.drawable.transport); categoryLookup.put("Infra", R.drawable.infra); categoryLookup.put("CBRNE", R.drawable.cbrne); categoryLookup.put("Other", R.drawable.other); } Map<String, Integer> severityLookup = new HashMap<>(); { severityLookup.put("Extreme", Notification.PRIORITY_HIGH); severityLookup.put("Severe", Notification.PRIORITY_LOW); severityLookup.put("Moderate", Notification.PRIORITY_MIN); severityLookup.put("Minor", Notification.PRIORITY_MIN); severityLookup.put("Unknown", Notification.PRIORITY_MIN); } if (alerts.size() > 0) { String msg = alerts.get(0).event; final NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); final Integer desc_cap_category = categoryLookup.get(alerts.get(0).category); final Integer notif_priority = severityLookup.get(alerts.get(0).severity); final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intentAction, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT); final Notification notification = new NotificationCompat.Builder(context) .setSmallIcon(desc_cap_category).setContentTitle(msg).setContentText("") .setContentIntent(pendingIntent).setAutoCancel(true).setPriority(notif_priority) .getNotification(); mNotificationManager.notify(R.string.notification_number, notification); } }
From source file:com.ayogo.cordova.notification.ScheduledNotificationManager.java
public void showNotification(ScheduledNotification scheduledNotification) { LOG.v(NotificationPlugin.TAG, "showNotification: " + scheduledNotification.toString()); NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); // Build the notification options builder.setDefaults(Notification.DEFAULT_ALL).setTicker(scheduledNotification.body) .setPriority(Notification.PRIORITY_HIGH).setAutoCancel(true); // TODO: add sound support // if (scheduledNotification.sound != null) { // builder.setSound(sound); // }/*from ww w . ja v a 2 s. com*/ if (scheduledNotification.body != null) { builder.setContentTitle(scheduledNotification.title); builder.setContentText(scheduledNotification.body); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(scheduledNotification.body)); } else { //Default the title to the app name try { PackageManager pm = context.getPackageManager(); ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); String appName = applicationInfo.loadLabel(pm).toString(); builder.setContentTitle(appName); builder.setContentText(scheduledNotification.title); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(scheduledNotification.title)); } catch (NameNotFoundException e) { LOG.v(NotificationPlugin.TAG, "Failed to set title for notification!"); return; } } if (scheduledNotification.badge != null) { LOG.v(NotificationPlugin.TAG, "showNotification: has a badge!"); builder.setSmallIcon(getResIdForDrawable(scheduledNotification.badge)); } else { LOG.v(NotificationPlugin.TAG, "showNotification: has no badge, use app icon!"); try { PackageManager pm = context.getPackageManager(); ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); Resources resources = pm.getResourcesForApplication(applicationInfo); builder.setSmallIcon(applicationInfo.icon); } catch (NameNotFoundException e) { LOG.v(NotificationPlugin.TAG, "Failed to set badge for notification!"); return; } } if (scheduledNotification.icon != null) { LOG.v(NotificationPlugin.TAG, "showNotification: has an icon!"); builder.setLargeIcon(getIconFromUri(scheduledNotification.icon)); } else { LOG.v(NotificationPlugin.TAG, "showNotification: has no icon, use app icon!"); try { PackageManager pm = context.getPackageManager(); ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); Resources resources = pm.getResourcesForApplication(applicationInfo); Bitmap appIconBitmap = BitmapFactory.decodeResource(resources, applicationInfo.icon); builder.setLargeIcon(appIconBitmap); } catch (NameNotFoundException e) { LOG.v(NotificationPlugin.TAG, "Failed to set icon for notification!"); return; } } Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); launchIntent.setAction("notification"); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); LOG.v(NotificationPlugin.TAG, "notify!"); notificationManager.notify(scheduledNotification.tag.hashCode(), notification); }
From source file:com.fimo_pitch.main.MainActivity.java
private void makeNotification(Context context, String title, String content) { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setSound(uri) .setPriority(Notification.PRIORITY_HIGH).setContentText(content); Intent resultIntent = new Intent(context, MainActivity.class); userModel = getUserModel();/*www .j a va 2s . c o m*/ resultIntent.putExtra(CONSTANT.KEY_USER, userModel); resultIntent.putExtra(CONSTANT.FROM_NOTIFICATION, "true"); TaskStackBuilder stackBuilder = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(FirstActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(10, mBuilder.build()); // Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // v.vibrate(ZAQ500); } else { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(10, mBuilder.build()); // Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // v.vibrate(500); } }
From source file:eu.nerdz.app.messenger.GcmIntentService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private synchronized void notifyUser(String from, int fromId, String message) { from = Html.fromHtml(from).toString(); message = Html.fromHtml(message).toString(); if (this.isActivityOpen()) { Log.d(TAG, "Activity is open"); Message message1 = this.makeMessage(from, fromId, message); Intent intent = new Intent(GcmIntentService.MESSAGE_EVENT); intent.putExtra(GcmIntentService.MESSAGE_EVENT, message1); this.mLocalBroadcastManager.sendBroadcast(intent); return;//from ww w.ja va 2 s .com } message = GcmIntentService.ellipsize(message, 60); String ticker = from + ": " + message; NotificationCompat.Builder builder = new NotificationCompat.Builder(this); int counter = MessagesHolder.append(from, message); Log.d(TAG, "" + counter); PendingIntent openIntent = null; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); if (counter > 1) { NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); from = String.format(this.getString(R.string.notify_new_messages), counter); message = this.getString(R.string.notify_swipe); style.setBigContentTitle(from); style.setSummaryText(Server.getInstance().getName()); for (Pair<String, String> pair : MessagesHolder.get()) { style.addLine( Html.fromHtml("<b>" + GcmIntentService.ellipsize(pair.first, 20) + "</b> " + pair.second)); } builder.setStyle(style); stackBuilder.addParentStack(ConversationsListActivity.class); stackBuilder.addNextIntent(new Intent(this, ConversationsListActivity.class)); openIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); } else { stackBuilder.addParentStack(ConversationActivity.class); Intent intent = new Intent(this, ConversationActivity.class); intent.putExtra(Keys.FROM, from); intent.putExtra(Keys.FROM_ID, fromId); stackBuilder.addNextIntent(intent); openIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); } builder //Sorry Robertof, no enormous oneliners today .setSmallIcon(R.drawable.ic_stat).setContentTitle(from).setContentText(message) .setContentIntent(openIntent).setDefaults(Notification.DEFAULT_ALL).setNumber(counter) .setTicker(ticker); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { builder.setPriority(Notification.PRIORITY_HIGH); } this.mNotificationManager.notify(MSG_ID, builder.build()); }
From source file:dk.dr.radio.afspilning.AfspillerIkonOgNotifikation.java
@SuppressLint("NewApi") public static Notification lavNotification(Context ctx) { String kanalNavn = ""; try {/*from w w w.ja va2 s .c o m*/ kanalNavn = DRData.instans.afspiller.getLydkilde().getKanal().navn; } catch (Exception e) { Log.rapporterFejl(e); } // TODO fjern try-catch efter nogle mneder i drift. 9. okt 2014 NotificationCompat.Builder b = new NotificationCompat.Builder(ctx).setSmallIcon(R.drawable.dr_notifikation) .setContentTitle(ctx.getString(R.string.dr_radio)).setContentText(kanalNavn).setOngoing(true) .setAutoCancel(false).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setPriority(1001) // holder den verst .setContentIntent(PendingIntent.getActivity(ctx, 0, new Intent(ctx, Hovedaktivitet.class), 0)); // PendingIntent er til at pege p aktiviteten der skal startes hvis // brugeren vlger notifikationen b.setContent( AfspillerIkonOgNotifikation.lavRemoteViews(AfspillerIkonOgNotifikation.TYPE_notifikation_lille)); Notification notification = b.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // A notification's big view appears only when the notification is expanded, // which happens when the notification is at the top of the notification drawer, // or when the user expands the notification with a gesture. // Expanded notifications are available starting with Android 4.1. notification.bigContentView = AfspillerIkonOgNotifikation .lavRemoteViews(AfspillerIkonOgNotifikation.TYPE_notifikation_stor); } notification.flags |= (Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT | Notification.PRIORITY_HIGH | Notification.FLAG_FOREGROUND_SERVICE); return notification; }
From source file:at.flack.receiver.EMailReceiver.java
@Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras();// w w w . j av a2 s . c om try { if (bundle.getString("type").equals("mail")) { sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); if (!sharedPrefs.getBoolean("notification_mail", true)) return; notify = sharedPrefs.getBoolean("notifications", true); vibrate = sharedPrefs.getBoolean("vibration", true); headsup = sharedPrefs.getBoolean("headsup", true); led_color = sharedPrefs.getInt("notification_light", -16776961); boolean all = sharedPrefs.getBoolean("all_mail", true); if (notify == false) return; NotificationCompat.Builder mBuilder = null; boolean use_profile_picture = false; Bitmap profile_picture = null; String origin_name = bundle.getString("senderName").equals("") ? bundle.getString("senderMail") : bundle.getString("senderName"); try { profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap( ProfilePictureCache.getInstance(context).get(origin_name), 200, 200, false), 300); use_profile_picture = true; } catch (Exception e) { use_profile_picture = false; } Resources res = context.getResources(); int lastIndex = bundle.getString("subject").lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(0, lastIndex))) { mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name) .setColor(0xFFFF5722) .setContentText(res.getString(R.string.sms_receiver_new_encrypted_mail)) .setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { if (bundle.getString("subject").charAt(0) == '%' && (bundle.getString("subject").length() == 10 || bundle.getString("subject").length() == 9)) { if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFFF5722) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else if (bundle.getString("subject").charAt(0) == '%' && bundle.getString("subject").length() >= 120 && bundle.getString("subject").length() < 125) { if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFFF5722) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else if (all) { // normal message mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name) .setColor(0xFFFF5722).setContentText(bundle.getString("subject")) .setAutoCancel(true).setStyle( new NotificationCompat.BigTextStyle().bigText(bundle.getString("subject"))); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } // } Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); mBuilder.setLights(led_color, 750, 4000); if (vibrate) { mBuilder.setVibrate(new long[] { 0, 100, 200, 300 }); } Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.putExtra("MAIL", bundle.getString("senderMail")); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); if (Build.VERSION.SDK_INT >= 16 && headsup) mBuilder.setPriority(Notification.PRIORITY_HIGH); if (Build.VERSION.SDK_INT >= 21) mBuilder.setCategory(Notification.CATEGORY_MESSAGE); final NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (!MainActivity.isOnTop) mNotificationManager.notify(9, mBuilder.build()); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.nutsuser.ridersdomain.activities.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from w w w . j a va 2s . co m*/ */ /* private void sendNotification(String message, long number_push) { Log.e("message: ", "" + message); *//* try { *//**//* mJsonObject = new JSONObject(message); // mStringType = mJson_Object.getString("type"); mStringUsername = mJson_Object.getString("username"); senderUserId = mJson_Object.getInt("sender_user_id"); mStringMessage = mJson_Object.getString("message"); Log.e("mStringMessage: ", "" + mStringMessage);*//**//* } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); }*//* // Intent intent = new Intent(this, MessagesActivity.class); //intent.putExtra("message_username", mStringUsername); //intent.putExtra("whrlocation", "notification"); //intent.putExtra("userId2", senderUserId); // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); //Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), // R.drawable.ic_launcher); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Rider Opinion") .setContentText(message) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); notificationBuilder.setPriority(Notification.PRIORITY_HIGH); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify((int) number_push *//**//* ID of notification *//**//*, notificationBuilder.build()); }*/ //This method is generating a notification and displaying the notification private void sendNotification(String message) { Intent intent = new Intent(this, NotificationListActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); int requestCode = 0; PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.app_icon).setContentTitle("Rider Opinion").setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); notificationBuilder.setPriority(Notification.PRIORITY_HIGH); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
From source file:com.example.android.wearable.wear.wearnotifications.handlers.BigPictureSocialIntentService.java
private NotificationCompat.Builder recreateBuilderWithBigPictureStyle() { // Main steps for building a BIG_PICTURE_STYLE notification (for more detailed comments on // building this notification, check StandaloneMainActivity.java): // 0. Get your data // 1. Build the BIG_PICTURE_STYLE // 2. Set up main Intent for notification // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification // 4. Build and issue the notification // 0. Get your data (everything unique per Notification) MockDatabase.BigPictureStyleSocialAppData bigPictureStyleSocialAppData = MockDatabase .getBigPictureStyleData();//w w w. j a va2 s. com // 1. Build the BIG_PICTURE_STYLE BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle() .bigPicture( BitmapFactory.decodeResource(getResources(), bigPictureStyleSocialAppData.getBigImage())) .setBigContentTitle(bigPictureStyleSocialAppData.getBigContentTitle()) .setSummaryText(bigPictureStyleSocialAppData.getSummaryText()); // 2. Set up main Intent for notification Intent mainIntent = new Intent(this, BigPictureSocialMainActivity.class); PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); // 3. Set up a RemoteInput Action, so users can input (keyboard, drawing, voice) directly // from the notification without entering the app. String replyLabel = getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT) .setLabel(replyLabel).setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses()).build(); Intent replyIntent = new Intent(this, BigPictureSocialIntentService.class); replyIntent.setAction(BigPictureSocialIntentService.ACTION_COMMENT); PendingIntent replyActionPendingIntent = PendingIntent.getService(this, 0, replyIntent, 0); // Enable action to appear inline on Wear 2.0 (24+). This means it will appear over the // lower portion of the Notification for easy action (only possible for one action). final NotificationCompat.Action.WearableExtender inlineActionForWear2 = new NotificationCompat.Action.WearableExtender() .setHintDisplayActionInline(true).setHintLaunchesActivity(false); NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent).addRemoteInput(remoteInput) // Add WearableExtender to enable inline actions .extend(inlineActionForWear2).build(); // 4. Build and issue the notification NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder( getApplicationContext()); GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); // Build notification notificationCompatBuilder.setStyle(bigPictureStyle) .setContentTitle(bigPictureStyleSocialAppData.getContentTitle()) .setContentText(bigPictureStyleSocialAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent).setColor(getResources().getColor(R.color.colorPrimary)) .setSubText(Integer.toString(1)).addAction(replyAction).setCategory(Notification.CATEGORY_SOCIAL) .setPriority(Notification.PRIORITY_HIGH).setVisibility(Notification.VISIBILITY_PRIVATE) .extend(new NotificationCompat.WearableExtender().setHintContentIntentLaunchesActivity(true)); for (String name : bigPictureStyleSocialAppData.getParticipants()) { notificationCompatBuilder.addPerson(name); } return notificationCompatBuilder; }
From source file:at.flack.receiver.SmsReceiver.java
@Override public void onReceive(Context context, Intent intent) { sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); notify = sharedPrefs.getBoolean("notifications", true); vibrate = sharedPrefs.getBoolean("vibration", true); headsup = sharedPrefs.getBoolean("headsup", true); led_color = sharedPrefs.getInt("notification_light", -16776961); boolean all = sharedPrefs.getBoolean("all_sms", true); if (notify == false) return;//from ww w .j a v a 2s. com Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = ""; if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i = 0; i < msgs.length; i++) { msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); str += msgs[i].getMessageBody().toString(); str += "\n"; } NotificationCompat.Builder mBuilder; if (main != null) { main.addNewMessage(str); return; } boolean use_profile_picture = false; Bitmap profile_picture = null; String origin_name = null; try { origin_name = getContactName(context, msgs[0].getDisplayOriginatingAddress()); if (origin_name == null) origin_name = msgs[0].getDisplayOriginatingAddress(); } catch (Exception e) { } if (origin_name == null) origin_name = "Unknown"; try { profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap( fetchThumbnail(context, msgs[0].getDisplayOriginatingAddress()), 200, 200, false), 300); use_profile_picture = true; } catch (Exception e) { use_profile_picture = false; } Resources res = context.getResources(); int positionOfBase64End = str.lastIndexOf("="); if (positionOfBase64End > 0 && Base64.isBase64(str.substring(0, positionOfBase64End))) { mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.raven_notification_icon) .setContentTitle(origin_name).setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_new_encrypted)).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else if (str.toString().charAt(0) == '%' && (str.toString().length() == 10 || str.toString().length() == 9)) { int lastIndex = str.toString().lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.raven_notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else if (str.toString().charAt(0) == '%' && str.toString().length() >= 120 && str.toString().length() < 125) { // DH Handshake int lastIndex = str.toString().lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.raven_notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else { // unencrypted messages if (all) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C).setContentText(str).setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(str)) .setSmallIcon(R.drawable.raven_notification_icon); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); mBuilder.setLights(led_color, 750, 4000); if (vibrate) { mBuilder.setVibrate(new long[] { 0, 100, 200, 300 }); } Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); resultIntent.putExtra("CONTACT_NUMBER", msgs[0].getOriginatingAddress()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); if (Build.VERSION.SDK_INT >= 16 && headsup) mBuilder.setPriority(Notification.PRIORITY_HIGH); if (Build.VERSION.SDK_INT >= 21) mBuilder.setCategory(Notification.CATEGORY_MESSAGE); final NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED") && !MainActivity.isOnTop) mNotificationManager.notify(7, mBuilder.build()); // Save SMS if default app if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && Telephony.Sms.getDefaultSmsPackage(context).equals(context.getPackageName())) { ContentValues values = new ContentValues(); values.put("address", msgs[0].getDisplayOriginatingAddress()); values.put("body", str.replace("\n", "").replace("\r", "")); if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) context.getContentResolver().insert(Telephony.Sms.Inbox.CONTENT_URI, values); } } }