public void addSummaryActions(Builder builder, NotificationData notificationData) { NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); addMarkAllAsReadAction(wearableExtender, notificationData); if (isDeleteActionAvailableForWear()) { addDeleteAllAction(wearableExtender, notificationData); } Account account = notificationData.getAccount(); if (isArchiveActionAvailableForWear(account)) { addArchiveAllAction(wearableExtender, notificationData); } builder.extend(wearableExtender); }
private void addWearActions(Builder builder, Account account, NotificationHolder holder) { NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); addReplyAction(wearableExtender, holder); addMarkAsReadAction(wearableExtender, holder); if (isDeleteActionAvailableForWear()) { addDeleteAction(wearableExtender, holder); } if (isArchiveActionAvailableForWear(account)) { addArchiveAction(wearableExtender, holder); } if (isSpamActionAvailableForWear(account)) { addMarkAsSpamAction(wearableExtender, holder); } builder.extend(wearableExtender); }
@Override public Notification[] buildNotifications(Context context, BuildOptions options) { Notification secondPage = new NotificationCompat.Builder(context) .setContentTitle(context.getString(R.string.second_page_content_title)) .setContentText(context.getString(R.string.second_page_content_text)) .build(); Builder notificationBuilder = buildBasicNotification(context, options); Notification twoPageNotification = new WearableExtender() .addPage(secondPage) .extend(notificationBuilder) .build(); return new Notification[] { twoPageNotification }; }
public static void showNotificationWithPages(Context context) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(context.getString(R.string.page1_title)) .setContentText(context.getString(R.string.page1_text)); Notification second = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(context.getString(R.string.page2_title)) .setContentText(context.getString(R.string.page2_text)) .build(); NotificationManagerCompat.from(context).notify(getNewID(), new WearableExtender() .addPage(second) .extend(builder) .build()); }
public static void showNotificationWithInputForPrimaryAction(Context context) { Intent intent = new Intent(ACTION_TEST); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); RemoteInput remoteInput = new RemoteInput.Builder(ACTION_EXTRA) .setLabel(context.getString(R.string.action_label)) .setChoices(context.getResources().getStringArray(R.array.input_choices)) .build(); NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_launcher, "Action", pendingIntent) .addRemoteInput(remoteInput) .build(); NotificationManagerCompat.from(context).notify(getNewID(), new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(context.getString(R.string.action_title)) .setContentText(context.getString(R.string.action_text)) .setContentIntent(pendingIntent) .extend(new WearableExtender().addAction(action)) .build()); }
public static void showNotificationWithInputForSecondaryAction(Context context) { Intent intent = new Intent(ACTION_TEST); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); RemoteInput remoteInput = new RemoteInput.Builder(ACTION_EXTRA) .setLabel(context.getString(R.string.action_label)) .build(); NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_launcher, "Action", pendingIntent) .addRemoteInput(remoteInput) .build(); NotificationManagerCompat.from(context).notify(getNewID(), new NotificationCompat.Builder(context) .setContentTitle(context.getString(R.string.action_title)) .extend(new WearableExtender().addAction(action)) .build()); }
private void addMarkAllAsReadAction(WearableExtender wearableExtender, NotificationData notificationData) { int icon = R.drawable.ic_action_mark_as_read_dark; String title = context.getString(R.string.notification_action_mark_all_as_read); Account account = notificationData.getAccount(); ArrayList<MessageReference> messageReferences = notificationData.getAllMessageReferences(); int notificationId = NotificationIds.getNewMailSummaryNotificationId(account); PendingIntent action = actionCreator.getMarkAllAsReadPendingIntent(account, messageReferences, notificationId); NotificationCompat.Action markAsReadAction = new NotificationCompat.Action.Builder(icon, title, action).build(); wearableExtender.addAction(markAsReadAction); }
private void addDeleteAllAction(WearableExtender wearableExtender, NotificationData notificationData) { int icon = R.drawable.ic_action_delete_dark; String title = context.getString(R.string.notification_action_delete_all); Account account = notificationData.getAccount(); ArrayList<MessageReference> messageReferences = notificationData.getAllMessageReferences(); int notificationId = NotificationIds.getNewMailSummaryNotificationId(account); PendingIntent action = actionCreator.getDeleteAllPendingIntent(account, messageReferences, notificationId); NotificationCompat.Action deleteAction = new NotificationCompat.Action.Builder(icon, title, action).build(); wearableExtender.addAction(deleteAction); }
private void addArchiveAllAction(WearableExtender wearableExtender, NotificationData notificationData) { int icon = R.drawable.ic_action_archive_dark; String title = context.getString(R.string.notification_action_archive_all); Account account = notificationData.getAccount(); ArrayList<MessageReference> messageReferences = notificationData.getAllMessageReferences(); int notificationId = NotificationIds.getNewMailSummaryNotificationId(account); PendingIntent action = actionCreator.createArchiveAllPendingIntent(account, messageReferences, notificationId); NotificationCompat.Action archiveAction = new NotificationCompat.Action.Builder(icon, title, action).build(); wearableExtender.addAction(archiveAction); }
private void addReplyAction(WearableExtender wearableExtender, NotificationHolder holder) { int icon = R.drawable.ic_action_single_message_options_dark; String title = context.getString(R.string.notification_action_reply); MessageReference messageReference = holder.content.messageReference; int notificationId = holder.notificationId; PendingIntent action = actionCreator.createReplyPendingIntent(messageReference, notificationId); NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(icon, title, action).build(); wearableExtender.addAction(replyAction); }
private void addMarkAsReadAction(WearableExtender wearableExtender, NotificationHolder holder) { int icon = R.drawable.ic_action_mark_as_read_dark; String title = context.getString(R.string.notification_action_mark_as_read); MessageReference messageReference = holder.content.messageReference; int notificationId = holder.notificationId; PendingIntent action = actionCreator.createMarkMessageAsReadPendingIntent(messageReference, notificationId); NotificationCompat.Action markAsReadAction = new NotificationCompat.Action.Builder(icon, title, action).build(); wearableExtender.addAction(markAsReadAction); }
private void addDeleteAction(WearableExtender wearableExtender, NotificationHolder holder) { int icon = R.drawable.ic_action_delete_dark; String title = context.getString(R.string.notification_action_delete); MessageReference messageReference = holder.content.messageReference; int notificationId = holder.notificationId; PendingIntent action = actionCreator.createDeleteMessagePendingIntent(messageReference, notificationId); NotificationCompat.Action deleteAction = new NotificationCompat.Action.Builder(icon, title, action).build(); wearableExtender.addAction(deleteAction); }
private void addArchiveAction(WearableExtender wearableExtender, NotificationHolder holder) { int icon = R.drawable.ic_action_archive_dark; String title = context.getString(R.string.notification_action_archive); MessageReference messageReference = holder.content.messageReference; int notificationId = holder.notificationId; PendingIntent action = actionCreator.createArchiveMessagePendingIntent(messageReference, notificationId); NotificationCompat.Action archiveAction = new NotificationCompat.Action.Builder(icon, title, action).build(); wearableExtender.addAction(archiveAction); }
private void addMarkAsSpamAction(WearableExtender wearableExtender, NotificationHolder holder) { int icon = R.drawable.ic_action_spam_dark; String title = context.getString(R.string.notification_action_spam); MessageReference messageReference = holder.content.messageReference; int notificationId = holder.notificationId; PendingIntent action = actionCreator.createMarkMessageAsSpamPendingIntent(messageReference, notificationId); NotificationCompat.Action spamAction = new NotificationCompat.Action.Builder(icon, title, action).build(); wearableExtender.addAction(spamAction); }
@Override public boolean matches(Object argument) { if (!(argument instanceof WearableExtender)) { return false; } WearableExtender wearableExtender = (WearableExtender) argument; for (Action action : wearableExtender.getActions()) { if (action.icon == icon && action.title.equals(title) && action.actionIntent == pendingIntent) { return true; } } return false; }
@Override public boolean matches(Object argument) { if (!(argument instanceof WearableExtender)) { return false; } WearableExtender wearableExtender = (WearableExtender) argument; return wearableExtender.getActions().size() == expectedNumberOfActions; }
/** * This method is just like a wrapper class method for usual notification class which add voice actions * for wearable devices * * @throws RuntimeException */ public void sendNotification() throws Exception { if (pendingIntent == null && notificationHandler == null) { throw new RuntimeException("Either pendingIntent or handler class requires."); } //Action action = buildWearableAction(); removed remote input action for now Notification notification = notificationBuilder.extend(new WearableExtender()).build(); if (ApplozicClient.getInstance(mContext).isNotificationSmallIconHidden() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { int smallIconViewId = mContext.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName()); if (smallIconViewId != 0) { if (notification.contentIntent != null) { notification.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (notification.headsUpContentView != null) { notification.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE); } if (notification.bigContentView != null) { notification.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE); } } } } NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mContext); notificationManager.notify(notificationId, notification); }
/** * This method is just like a wrapper class method for usual notification class which add voice actions * for wearable devices * * @throws RuntimeException */ public void sendNotification() throws Exception { if (pendingIntent == null && notificationHandler == null) { throw new RuntimeException("Either pendingIntent or handler class requires."); } //Action action = buildWearableAction(); removed remote input action for now Notification notification = notificationBuilder.extend(new WearableExtender()).build(); if (ApplozicClient.getInstance(mContext).isNotificationSmallIconHidden() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { int smallIconViewId = mContext.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName()); if (smallIconViewId != 0) { if (notification.contentIntent != null && notification.contentView != null) { notification.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (notification.headsUpContentView != null) { notification.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE); } if (notification.bigContentView != null) { notification.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE); } } } } NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mContext); notificationManager.notify(notificationId, notification); }
private void VoicePrintWearNotificationView() { // Key for the string that's delivered in the action's intent String replyLabel = getResources().getString(R.string.reply_choices); RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(replyLabel) .build(); // Create an intent for the reply action Intent replyIntent = new Intent(this, OtherActivity.class); PendingIntent replyPendingIntent = PendingIntent.getActivity(this, 0, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Create the reply action and add the remote input NotificationCompat.Action action = new NotificationCompat.Action.Builder( R.drawable.ic_launcher, getString(R.string.label, replyPendingIntent), replyPendingIntent).addRemoteInput(remoteInput).build(); // Build the notification and add the action via WearableExtender Notification notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("消息标题") .setContentText("消息正文").extend(new WearableExtender().addAction(action)).build(); // Issue the notification NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(NOTIFICATION_ID_6, notification); manager.cancel(NOTIFICATION_ID_5); manager.cancel(NOTIFICATION_ID_4); manager.cancel(NOTIFICATION_ID_3); manager.cancel(NOTIFICATION_ID_2); manager.cancel(NOTIFICATION_ID_1); }
private void MorePagesWearNotificationView() { // Create builder for the main notification Intent viewIntent = new Intent(this, SpecialActivity.class); PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, viewIntent, 0); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("第一页") .setContentText("亲,还有第二页噢").setContentIntent(viewPendingIntent); // Create a big text style for the second page BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle(); secondPageStyle.setBigContentTitle("第二页").bigText( "这是一段很长的Text,用来测试用!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); // Create second page notification Notification secondPageNotification = new NotificationCompat.Builder(this).setStyle( secondPageStyle).build(); // Add second page with wearable extender and extend the main // notification Notification twoPageNotification = new WearableExtender().addPage(secondPageNotification) .extend(notificationBuilder).build(); // Issue the notification NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(NOTIFICATION_ID_5, twoPageNotification); manager.cancel(NOTIFICATION_ID_4); manager.cancel(NOTIFICATION_ID_6); manager.cancel(NOTIFICATION_ID_3); manager.cancel(NOTIFICATION_ID_2); manager.cancel(NOTIFICATION_ID_1); }
private void ReplyWearNotificationView() { // Create an intent for the reply action Intent actionIntent = new Intent(this, SpecialActivity.class); PendingIntent actionPendingIntent = PendingIntent.getActivity(this, 0, actionIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Create the action NotificationCompat.Action action = new NotificationCompat.Action.Builder( R.drawable.ic_launcher, getString(R.string.label, actionPendingIntent), actionPendingIntent).build(); // Build the notification and add the action via WearableExtender Notification notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.hello_world)) .extend(new NotificationCompat.WearableExtender() .setContentIcon(R.drawable.ic_launcher)) /* .extend(new WearableExtender().addAction(action)) */ .setDefaults(NotificationCompat.DEFAULT_VIBRATE)//增加震动 .build(); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(NOTIFICATION_ID_3, notificationBuilder); manager.cancel(NOTIFICATION_ID_2); manager.cancel(NOTIFICATION_ID_5); manager.cancel(NOTIFICATION_ID_4); manager.cancel(NOTIFICATION_ID_6); manager.cancel(NOTIFICATION_ID_1); }
void onlywearableNoti() { //create the intent to launch the notiactivity, then the pentingintent. Intent viewIntent = new Intent(this, NotiActivity.class); viewIntent.putExtra("NotiID", "Notification ID is " + notificationID); PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, viewIntent, 0); // we are going to add an intent to open the camera here. Intent cameraIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); PendingIntent cameraPendingIntent = PendingIntent.getActivity(this, 0, cameraIntent, 0); // Create the action NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_action_time, "take a Picutre", cameraPendingIntent) .build(); //Now create the notification. We must use the NotificationCompat or it will not work on the wearable. NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("add button Noti") .setContentText("swipe left to open camera.") .setContentIntent(viewPendingIntent) .extend(new WearableExtender().addAction(action)); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); // Build the notification and issues it with notification manager. notificationManager.notify(notificationID, notificationBuilder.build()); notificationID++; }
void onlywearableNoti() { //create the intent to launch the notiactivity, then the pentingintent. Intent viewIntent = new Intent(this, NotiActivity.class); viewIntent.putExtra("NotiID", "Notification ID is " + notificationID); PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, viewIntent, 0); // we are going to add an intent to open the camera here. Intent cameraIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); PendingIntent cameraPendingIntent = PendingIntent.getActivity(this, 0, cameraIntent, 0); // Create the action NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_action_time, "Open Camera", cameraPendingIntent) .build(); //Now create the notification. We must use the NotificationCompat or it will not work on the wearable. NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, id) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Button on Wear Only") .setContentText("tap to open message") .setContentIntent(viewPendingIntent) .setChannelId(id) .extend(new WearableExtender().addAction(action)); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); // Build the notification and issues it with notification manager. notificationManager.notify(notificationID, notificationBuilder.build()); notificationID++; }
private WearableExtender action(int icon, String title, PendingIntent pendingIntent) { return argThat(new ActionMatcher(icon, title, pendingIntent)); }
private WearableExtender numberOfActions(int expectedNumberOfActions) { return argThat(new NumberOfActionsMatcher(expectedNumberOfActions)); }