List of usage examples for android.app Notification DEFAULT_VIBRATE
int DEFAULT_VIBRATE
To view the source code for android.app Notification DEFAULT_VIBRATE.
Click Source Link
From source file:org.transdroid.service.UpdateService.java
private void newNotification(String ticker, String title, String text, String downloadUrl, int notifyID) { // Use the alarm service settings for the notification sound/vibrate/colour SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); AlarmSettings settings = Preferences.readAlarmSettings(prefs); // Set up an intent that will initiate a download of the new version Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadUrl)); // Create a new notification Notification newNotification = new Notification(R.drawable.icon_notification, ticker, System.currentTimeMillis()); newNotification.flags = Notification.FLAG_AUTO_CANCEL; newNotification.setLatestEventInfo(getApplicationContext(), title, text, PendingIntent.getActivity(getApplicationContext(), notifyID, i, 0)); // Get the system notification manager, if not done so previously if (notificationManager == null) { notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); }/*from w w w .j a va2s . c o m*/ // If sound enabled add to notification if (settings.getAlarmPlaySound() && settings.getAlarmSoundURI() != null) { newNotification.sound = Uri.parse(settings.getAlarmSoundURI()); } // If vibration enabled add to notification if (settings.getAlarmVibrate()) { newNotification.defaults = Notification.DEFAULT_VIBRATE; } // Add coloured light; defaults to 0xff7dbb21 newNotification.ledARGB = settings.getAlarmColour(); newNotification.ledOnMS = 600; newNotification.ledOffMS = 1000; newNotification.flags |= Notification.FLAG_SHOW_LIGHTS; // Send notification notificationManager.notify(notifyID, newNotification); }
From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java
@SuppressWarnings("deprecation") public Notification createNotification(Bundle settings, JSONObject obj) { // notifications[i] = api.normalizeAPI({ // 'string': { // mandatory: ['title', 'body'], // defaults: {'icon':'icon'} // },/*from w w w . ja va2 s. com*/ // // 'number': { // mandatory: ['id', 'timeMillisSince1970'], // // the number of ms after which we start prioritising more recent // things above you. // defaults: {'epsilon': 1000 * 60 * 24 * 365} // }, // // 'boolean': { // defaults: { // 'vibrate': false, // 'sound': false // } // } int icon = settings.getInt("notification_icon", -1); if (icon == -1) { Log.e(C.TAG, "Need a notification_icon resource in the meta-data of LocalNotificationsAlarmReceiver"); return null; } Notification n = new Notification(); n.icon = icon; n.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; long alarmTime = obj.optLong("timeMillisSince1970"); long displayTime = obj.optLong("displayTimestamp", alarmTime); n.when = displayTime; n.tickerText = obj.optString("body"); n.setLatestEventInfo(mContext, obj.optString("title"), obj.optString("body"), null); if (obj.optBoolean("vibrate")) { n.defaults |= Notification.DEFAULT_VIBRATE; } if (obj.optBoolean("sound")) { n.defaults |= Notification.DEFAULT_SOUND; } String uriString = settings.getString("content_uri_prefix"); if (uriString == null) { Log.e(C.TAG, "Need a content_uri_prefix in the meta-data of LocalNotificationsAlarmReceiver"); return null; } if (uriString.contains("%d")) { uriString = String.format(uriString, obj.optInt("id")); } Uri uri = Uri.parse(uriString); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(uri); n.contentIntent = PendingIntent.getActivity(mContext, 23, intent, PendingIntent.FLAG_ONE_SHOT); return n; }
From source file:eu.inmite.apps.smsjizdenka.service.ListenerService.java
private void processNotification(DataMap dataMap) { DataMap dataMap1 = dataMap.getDataMap("notification"); Ticket ticket = new Ticket(); ticket.setId(dataMap1.getLong("id")); ticket.setCityId(dataMap1.getLong("city_id")); ticket.setCity(dataMap1.getString("city")); ticket.setStatus(dataMap1.getInt("status")); ticket.setHash(dataMap1.getString("hash")); ticket.setText(dataMap1.getString("text")); ticket.setValidFrom(dataMap1.getLong("valid_from")); ticket.setValidTo(dataMap1.getLong("valid_to")); ticket.setNotificationId(dataMap1.getLong("notification_id")); Intent notificationIntent = new Intent(this, NotificationActivity.class); notificationIntent.putExtra("ticket", ticket); PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); int notificationColor = 0; if (ticket.getStatus() == NotificationActivity.STATUS_VALID_EXPIRING) { notificationColor = getResources().getColor(R.color.background_city_yellow); } else if (ticket.getStatus() == NotificationActivity.STATUS_EXPIRING_EXPIRED) { notificationColor = getResources().getColor(R.color.background_city_red); } else if (ticket.getStatus() == NotificationActivity.STATUS_EXPIRED) { notificationColor = getResources().getColor(R.color.background_city_transparent); }/*from ww w .j a v a2 s. c om*/ // Create a big text style for the second page NotificationCompat.BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle(); secondPageStyle.setBigContentTitle(getResources().getString(R.string.sms)).bigText(ticket.getText()); Notification secondPageNotification = new NotificationCompat.Builder(this).setStyle(secondPageStyle) .build(); Intent intent = new Intent(this, OpenPhoneReceiver.class); intent.setAction("eu.inmite.apps.smsjizdenka.openphone"); intent.putExtra("ticket", ticket); PendingIntent openPhonePendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); int resourceIdForCity = Constants.CITIES_BACKGROUND_MAP.containsKey(ticket.getCityId()) ? Constants.CITIES_BACKGROUND_MAP.get(ticket.getCityId()) : 0; Notification notification = new Notification.Builder(this).setSmallIcon(R.drawable.ic_launcher) .setContentText(getStatusTitle(ticket)) .extend(new Notification.WearableExtender().setDisplayIntent(notificationPendingIntent) .setCustomContentHeight(getResources().getDimensionPixelSize(R.dimen.notification_size)) .setStartScrollBottom(true) .setBackground(ImageUtil.combineTwoImages(this, resourceIdForCity, notificationColor)) .addPage(secondPageNotification).addAction(new Notification.Action( R.drawable.go_to_phone_00156, "Open on phone", openPhonePendingIntent))) .build(); notification.defaults |= Notification.DEFAULT_VIBRATE; NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify((int) ticket.getNotificationId(), notification); }
From source file:com.example.product.GcmIntentService.java
private void sendNotification(Bundle extras) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); //largeicon ?? ? Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.mylogo_whitebackground); Resources res = getResources(); int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height); int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width); largeIcon = Bitmap.createScaledBitmap(largeIcon, width, height, false); //? ?? ? /*from w ww . java 2 s . c om*/ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.mylogo_whitebackground).setLargeIcon(largeIcon) .setTicker(extras.getString("stock_name") + " - " + extras.getString("signal_name")) .setContentTitle(extras.getString("stock_name")) //.setStyle(new NotificationCompat.BigTextStyle() // BigTextStyle? . //.bigText(msg)) //.setWhen() //? ? ?? ?. // ? ? ? ? 5? ?. .setNumber(5).setDefaults(Notification.DEFAULT_VIBRATE).setAutoCancel(true) .setContentText(extras.getString("signal_name")); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainDefaultNotifier.java
@Override public Boolean handleNotification(CapptainReachInteractiveContent content) throws RuntimeException { /* System notification case */ if (content.isSystemNotification()) { /* Big picture handling */ Bitmap bigPicture = null;//from www . j a v a 2 s . c o m String bigPictureURL = content.getNotificationBigPicture(); if (bigPictureURL != null && Build.VERSION.SDK_INT >= 16) { /* Schedule picture download if needed, or load picture if download completed. */ Long downloadId = content.getDownloadId(); if (downloadId == null) { NotificationUtilsV11.downloadBigPicture(mContext, content); return null; } else bigPicture = NotificationUtilsV11.getBigPicture(mContext, downloadId); } /* Generate notification identifier */ int notificationId = getNotificationId(content); /* Build notification using support lib to manage compatibility with old Android versions */ NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); /* Icon for ticker and content icon */ builder.setSmallIcon(mNotificationIcon); /* * Large icon, handled only since API Level 11 (needs down scaling if too large because it's * cropped otherwise by the system). */ Bitmap notificationImage = content.getNotificationImage(); if (notificationImage != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) builder.setLargeIcon(scaleBitmapForLargeIcon(mContext, notificationImage)); /* Texts */ String notificationTitle = content.getNotificationTitle(); String notificationMessage = content.getNotificationMessage(); String notificationBigText = content.getNotificationBigText(); builder.setContentTitle(notificationTitle); builder.setContentText(notificationMessage); /* * Replay: display original date and don't replay all the tickers (be as quiet as possible * when replaying). */ Long notificationFirstDisplayedDate = content.getNotificationFirstDisplayedDate(); if (notificationFirstDisplayedDate != null) builder.setWhen(notificationFirstDisplayedDate); else builder.setTicker(notificationTitle); /* Big picture */ if (bigPicture != null) builder.setStyle(new BigPictureStyle().bigPicture(bigPicture).setBigContentTitle(notificationTitle) .setSummaryText(notificationMessage)); /* Big text */ else if (notificationBigText != null) builder.setStyle(new BigTextStyle().bigText(notificationBigText)); /* Vibration/sound if not a replay */ if (notificationFirstDisplayedDate == null) { int defaults = 0; if (content.isNotificationSound()) defaults |= Notification.DEFAULT_SOUND; if (content.isNotificationVibrate()) defaults |= Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); } /* Launch the receiver on action */ Intent actionIntent = new Intent(INTENT_ACTION_ACTION_NOTIFICATION); CapptainReachAgent.setContentIdExtra(actionIntent, content); actionIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId); Intent intent = content.getIntent(); if (intent != null) actionIntent.putExtra(INTENT_EXTRA_COMPONENT, intent.getComponent()); actionIntent.setPackage(mContext.getPackageName()); PendingIntent contentIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(), actionIntent, FLAG_CANCEL_CURRENT); builder.setContentIntent(contentIntent); /* Also launch receiver if the notification is exited (clear button) */ Intent exitIntent = new Intent(INTENT_ACTION_EXIT_NOTIFICATION); exitIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId); CapptainReachAgent.setContentIdExtra(exitIntent, content); exitIntent.setPackage(mContext.getPackageName()); PendingIntent deleteIntent = PendingIntent.getBroadcast(mContext, (int) content.getLocalId(), exitIntent, FLAG_CANCEL_CURRENT); builder.setDeleteIntent(deleteIntent); /* Can be dismissed ? */ Notification notification = builder.build(); if (!content.isNotificationCloseable()) notification.flags |= Notification.FLAG_NO_CLEAR; /* Allow overriding */ if (onNotificationPrepared(notification, content)) /* * Submit notification, replacing the previous one if any (this should happen only if the * application process is restarted). */ mNotificationManager.notify(notificationId, notification); } /* Activity embedded notification case */ else { /* Get activity */ Activity activity = CapptainActivityManager.getInstance().getCurrentActivity().get(); /* Cannot notify in app if no activity provided */ if (activity == null) return false; /* Get notification area */ String category = content.getCategory(); int areaId = getInAppAreaId(category); View notificationAreaView = activity.findViewById(areaId); /* No notification area, check if we can install overlay */ if (notificationAreaView == null) { /* Check overlay is not disabled in this activity */ Bundle activityConfig = CapptainUtils.getActivityMetaData(activity); if (!activityConfig.getBoolean(METADATA_NOTIFICATION_OVERLAY, true)) return false; /* Inflate overlay layout and get reference to notification area */ View overlay = LayoutInflater.from(mContext).inflate(getOverlayLayoutId(category), null); activity.addContentView(overlay, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); notificationAreaView = activity.findViewById(areaId); } /* Otherwise check if there is an overlay containing the area to restore visibility */ else { View overlay = activity.findViewById(getOverlayViewId(category)); if (overlay != null) overlay.setVisibility(View.VISIBLE); } /* Make the notification area visible */ notificationAreaView.setVisibility(View.VISIBLE); /* Prepare area */ prepareInAppArea(content, notificationAreaView); } /* Success */ return true; }
From source file:com.teinproductions.tein.papyrosprogress.UpdateCheckReceiver.java
private static void issueNotification(Context context, Set<String> addedMilestones, Set<String> removedMilestones, Map<String, int[]> changedProgresses) { String title = context.getString(R.string.notification_title); StringBuilder message = new StringBuilder(); // Changed progresses for (String milestoneTitle : changedProgresses.keySet()) { int oldProgress = changedProgresses.get(milestoneTitle)[0]; int newProgress = changedProgresses.get(milestoneTitle)[1]; message.append("\n").append(String.format(context.getString(R.string.notific_msg_text_format), milestoneTitle, oldProgress, newProgress)); }// w w w.j a va 2 s. com // Added milestones for (String milestoneTitle : addedMilestones) { message.append("\n").append(context.getString(R.string.milestone_added_notification, milestoneTitle)); } // Removed milestones for (String milestoneTitle : removedMilestones) { message.append("\n").append(context.getString(R.string.milestone_removed_notification, milestoneTitle)); } // Remove first newline message.delete(0, 1); // Create PendingIntent PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); boolean sound = pref.getBoolean(Constants.NOTIFICATION_SOUND_PREF, true); boolean vibrate = pref.getBoolean(Constants.NOTIFICATION_VIBRATE_PREF, true); boolean light = pref.getBoolean(Constants.NOTIFICATION_LIGHT_PREF, true); int defaults = 0; if (sound) defaults = defaults | Notification.DEFAULT_SOUND; if (vibrate) defaults = defaults | Notification.DEFAULT_VIBRATE; if (light) defaults = defaults | Notification.DEFAULT_LIGHTS; // Build the notification NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setContentIntent(pendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setSmallIcon(R.mipmap.notification_small_icon) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setDefaults(defaults).setAutoCancel(true); // Issue the notification NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(PROGRESS_NOTIFICATION_ID, builder.build()); }
From source file:ru.appsm.inapphelp.IAHHelpDesk.java
/** * * Handle push notification. Cordova.//w ww . ja va 2 s. co m * * @param data * @param context */ public static void BuildNotificationForDataWithContext(JSONObject data, Context context) { Log.i(TAG, "Create notifications"); if (data != null && data.has("secretkey") && data.has("userid") && data.has("appkey") && data.has("appid") && data.has("email") && data.has("message") && data.has("title") && data.has("notId") && data.has("msgId")) { try { int notId = 1; try { notId = data.getInt("notId"); } catch (JSONException e) { notId = 1; } mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, IssueDetailActivity.class); notificationIntent.putExtra("fromPush", true); notificationIntent.putExtra("userid", data.getString("userid")); notificationIntent.putExtra("appid", data.getString("appid")); notificationIntent.putExtra("appkey", data.getString("appkey")); notificationIntent.putExtra("secretkey", data.getString("secretkey")); notificationIntent.putExtra("email", data.getString("email")); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(getApplicationIcon(context)).setContentTitle(data.getString("title")) .setContentText(data.getString("message")).setAutoCancel(true) .setContentIntent(contentIntent); if (data.getString("sound").equals("default")) { mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS); } mNotificationManager.notify(notId, mBuilder.build()); } catch (JSONException e) { Log.i(TAG, "Fail to parse push data"); } } else { Log.i(TAG, "Empty or wrong push data"); } }
From source file:uk.org.rivernile.edinburghbustracker.android.alerts.TimeAlertService.java
/** * {@inheritDoc}/* www . j a v a 2 s. c om*/ */ @Override protected void onHandleIntent(final Intent intent) { final String stopCode = intent.getStringExtra(ARG_STOPCODE); final String[] services = intent.getStringArrayExtra(ARG_SERVICES); final int timeTrigger = intent.getIntExtra(ARG_TIME_TRIGGER, 5); final BusParser parser = new EdinburghParser(); HashMap<String, BusStop> result; try { // Get the bus times. Only get 1 bus per service. result = parser.getBusStopData(new String[] { stopCode }, 1); } catch (BusParserException e) { // There was an error. No point continuing. Reschedule. reschedule(intent); return; } // Get the bus stop we are interested in. It should be the only one in // the HashMap anyway. final BusStop busStop = result.get(stopCode); int time; EdinburghBus edinBs; // Loop through all the bus services at this stop. for (BusService bs : busStop.getBusServices()) { // We are only interested in the next departure. Also get the time. edinBs = (EdinburghBus) bs.getFirstBus(); if (edinBs == null) { continue; } time = edinBs.getArrivalMinutes(); // Loop through all of the services we are interested in. for (String service : services) { // The service matches and meets the time criteria. if (service.equals(bs.getServiceName()) && time <= timeTrigger) { // The alert may have been cancelled by the user recently, // check it's still active to stay relevant. Cancel the // alert if we're continuing. if (!sd.isActiveTimeAlert(stopCode)) return; alertMan.removeTimeAlert(); // Create the intent that's fired when the notification is // tapped. It shows the bus times view for that stop. final Intent launchIntent = new Intent(this, DisplayStopDataActivity.class); launchIntent.setAction(DisplayStopDataActivity.ACTION_VIEW_STOP_DATA); launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); launchIntent.putExtra(DisplayStopDataActivity.ARG_STOPCODE, stopCode); launchIntent.putExtra(DisplayStopDataActivity.ARG_FORCELOAD, true); final String stopName = bsd.getNameForBusStop(stopCode); final String title = getString(R.string.timeservice_notification_title); final String summary = getResources().getQuantityString( R.plurals.timeservice_notification_summary, time == 0 ? 1 : time, service, time, stopName); // Build the notification. final NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this); notifBuilder.setAutoCancel(true); notifBuilder.setSmallIcon(R.drawable.ic_status_bus); notifBuilder.setTicker(summary); notifBuilder.setContentTitle(title); notifBuilder.setContentText(summary); // Support for Jelly Bean notifications. notifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(summary)); notifBuilder.setContentIntent( PendingIntent.getActivity(this, 0, launchIntent, PendingIntent.FLAG_ONE_SHOT)); final Notification n = notifBuilder.build(); if (sp.getBoolean(PreferencesActivity.PREF_ALERT_SOUND, true)) n.defaults |= Notification.DEFAULT_SOUND; if (sp.getBoolean(PreferencesActivity.PREF_ALERT_VIBRATE, true)) n.defaults |= Notification.DEFAULT_VIBRATE; if (sp.getBoolean(PreferencesActivity.PREF_ALERT_LED, true)) { n.defaults |= Notification.DEFAULT_LIGHTS; n.flags |= Notification.FLAG_SHOW_LIGHTS; } // Send the notification. notifMan.notify(ALERT_ID, n); return; } } } // All the services have been looped through and the criteria didn't // match. This means a reschedule should be attempted. reschedule(intent); }
From source file:com.gsma.rcs.ri.messaging.chat.single.SingleChatIntentService.java
/** * Generate a notification/*w w w .ja v a 2 s .co m*/ * * @param invitation invitation * @param title title * @param message message * @return the notification */ private Notification buildNotification(PendingIntent invitation, String title, String message) { NotificationCompat.Builder notif = new NotificationCompat.Builder(this); notif.setContentIntent(invitation); notif.setSmallIcon(R.drawable.ri_notif_chat_icon); notif.setWhen(System.currentTimeMillis()); notif.setAutoCancel(true); notif.setOnlyAlertOnce(true); notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); notif.setDefaults(Notification.DEFAULT_VIBRATE); notif.setContentTitle(title); notif.setContentText(message); return notif.build(); }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void refreshNotification(Context context, boolean noTimeline) { AppSettings settings = AppSettings.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int currentAccount = sharedPrefs.getInt("current_account", 1); //int[] unreadCounts = new int[] {4, 1, 2}; // for testing int[] unreadCounts = getUnreads(context); int timeline = unreadCounts[0]; int realTimelineCount = timeline; // if they don't want that type of notification, simply set it to zero if (!settings.timelineNot || (settings.pushNotifications && settings.liveStreaming) || noTimeline) { unreadCounts[0] = 0;//from w ww .j av a 2 s . co m } if (!settings.mentionsNot) { unreadCounts[1] = 0; } if (!settings.dmsNot) { unreadCounts[2] = 0; } if (unreadCounts[0] == 0 && unreadCounts[1] == 0 && unreadCounts[2] == 0) { } else { Intent markRead = new Intent(context, MarkReadService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); String shortText = getShortText(unreadCounts, context, currentAccount); String longText = getLongText(unreadCounts, context, currentAccount); // [0] is the full title and [1] is the screenname String[] title = getTitle(unreadCounts, context, currentAccount); boolean useExpanded = useExp(context); boolean addButton = addBtn(unreadCounts); if (title == null) { return; } Intent resultIntent; if (unreadCounts[1] != 0 && unreadCounts[0] == 0) { // it is a mention notification (could also have a direct message) resultIntent = new Intent(context, RedirectToMentions.class); } else if (unreadCounts[2] != 0 && unreadCounts[0] == 0 && unreadCounts[1] == 0) { // it is a direct message resultIntent = new Intent(context, RedirectToDMs.class); } else { resultIntent = new Intent(context, MainActivity.class); } PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title[0]) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)) .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(getIcon(context, unreadCounts, title[1])) .setContentIntent(resultPendingIntent).setAutoCancel(true) .setTicker(TweetLinkUtils.removeColorHtml(shortText, settings)) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (unreadCounts[1] > 1 && unreadCounts[0] == 0 && unreadCounts[2] == 0) { // inbox style notification for mentions mBuilder.setStyle(getMentionsInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else if (unreadCounts[2] > 1 && unreadCounts[0] == 0 && unreadCounts[1] == 0) { // inbox style notification for direct messages mBuilder.setStyle(getDMInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else { // big text style for an unread count on timeline, mentions, and direct messages mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title[0], shortText); } // Light Flow notification sendToLightFlow(context, title[0], shortText); int homeTweets = unreadCounts[0]; int mentionsTweets = unreadCounts[1]; int dmTweets = unreadCounts[2]; int newC = 0; if (homeTweets > 0) { newC++; } if (mentionsTweets > 0) { newC++; } if (dmTweets > 0) { newC++; } if (settings.notifications && newC > 0) { if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); if (addButton) { // the reply and read button should be shown Intent reply; if (unreadCounts[1] == 1) { reply = new Intent(context, NotificationCompose.class); } else { reply = new Intent(context, NotificationDMCompose.class); } Log.v("username_for_noti", title[1]); sharedPrefs.edit().putString("from_notification", "@" + title[1] + " " + title[2]).commit(); MentionsDataSource data = MentionsDataSource.getInstance(context); long id = data.getLastIds(currentAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0); sharedPrefs.edit().putLong("from_notification_long", id).commit(); sharedPrefs.edit() .putString("from_notification_text", "@" + title[1] + ": " + TweetLinkUtils.removeColorHtml(shortText, settings)) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel("@" + title[1] + " ").build(); // Create the notification action NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build(); NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder( R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending); mBuilder.addAction(replyAction); mBuilder.addAction(action.build()); } else { // otherwise, if they can use the expanded notifications, the popup button will be shown Intent popup = new Intent(context, RedirectToPopup.class); popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); popup.putExtra("from_notification", true); PendingIntent popupPending = PendingIntent.getActivity(context, 0, popup, 0); NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder( R.drawable.ic_popup, context.getResources().getString(R.string.popup), popupPending); mBuilder.addAction(action.build()); } // Build the notification and issues it with notification manager. notificationManager.notify(1, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } } // if there are unread tweets on the timeline, check them for favorite users if (settings.favoriteUserNotifications && realTimelineCount > 0) { favUsersNotification(currentAccount, context); } } try { ContentValues cv = new ContentValues(); cv.put("tag", "com.klinker.android.twitter/com.klinker.android.twitter.ui.MainActivity"); // add the direct messages and mentions cv.put("count", unreadCounts[1] + unreadCounts[2]); context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv); } catch (IllegalArgumentException ex) { /* Fine, TeslaUnread is not installed. */ } catch (Exception ex) { /* Some other error, possibly because the format of the ContentValues are incorrect. Log but do not crash over this. */ ex.printStackTrace(); } }