androidx.core.app.RemoteInput Java Examples
The following examples show how to use
androidx.core.app.RemoteInput.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AutoMessageReplyReceiver.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { ApplicationLoader.postInitApplication(); Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput == null) { return; } CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY); if (text == null || text.length() == 0) { return; } long dialog_id = intent.getLongExtra("dialog_id", 0); int max_id = intent.getIntExtra("max_id", 0); int currentAccount = intent.getIntExtra("currentAccount", 0); if (dialog_id == 0 || max_id == 0) { return; } SendMessagesHelper.getInstance(currentAccount).sendMessage(text.toString(), dialog_id, null, null, true, null, null, null, true, 0); MessagesController.getInstance(currentAccount).markDialogAsRead(dialog_id, max_id, max_id, 0, false, 0, true, 0); }
Example #2
Source File: VoiceNotiActivity.java From wearable with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_voice_noti); //note android developer page, shows this in a separate method, but not necessary. Bundle remoteInput = RemoteInput.getResultsFromIntent(getIntent()); if (remoteInput != null) { info = remoteInput.getCharSequence(EXTRA_VOICE_REPLY).toString(); } else { info = "No voice response."; } logger = findViewById(R.id.logger); logger.setText(info); }
Example #3
Source File: AutoMessageReplyReceiver.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { ApplicationLoader.postInitApplication(); Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput == null) { return; } CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY); if (text == null || text.length() == 0) { return; } long dialog_id = intent.getLongExtra("dialog_id", 0); int max_id = intent.getIntExtra("max_id", 0); int currentAccount = intent.getIntExtra("currentAccount", 0); if (dialog_id == 0 || max_id == 0) { return; } SendMessagesHelper.getInstance(currentAccount).sendMessage(text.toString(), dialog_id, null, null, true, null, null, null, true, 0); MessagesController.getInstance(currentAccount).markDialogAsRead(dialog_id, max_id, max_id, 0, false, 0, true, 0); }
Example #4
Source File: RemoteReplyReceiver.java From deltachat-android with GNU General Public License v3.0 | 6 votes |
@SuppressLint("StaticFieldLeak") @Override public void onReceive(final Context context, Intent intent) { if (!REPLY_ACTION.equals(intent.getAction())) return; Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); final int chatId = intent.getIntExtra(CHAT_ID_EXTRA, 0); if (remoteInput == null || chatId == 0) return; final CharSequence responseText = remoteInput.getCharSequence(EXTRA_REMOTE_REPLY); if (responseText != null) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { ApplicationDcContext dcContext = DcHelper.getContext(context); dcContext.sendTextMsg(chatId, responseText.toString()); dcContext.notificationCenter.removeNotifications(chatId); return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }
Example #5
Source File: QiscusPushNotificationClickReceiver.java From qiscus-sdk-android with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { QiscusComment comment = intent.getParcelableExtra("data"); Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { CharSequence message = remoteInput.getCharSequence(QiscusPushNotificationUtil.KEY_NOTIFICATION_REPLY); NotificationManager notificationManager = (NotificationManager) context.getSystemService( Context.NOTIFICATION_SERVICE); if (notificationManager != null) { notificationManager.cancel((int) comment.getRoomId()); } QiscusComment qiscusComment = QiscusComment.generateMessage(comment.getRoomId(), (String) message); Qiscus.getChatConfig().getReplyNotificationHandler().onSend(context, qiscusComment); } else { Qiscus.getChatConfig().getNotificationClickListener().onClick(context, comment); } }
Example #6
Source File: SingleRecipientNotificationBuilder.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
public void addAndroidAutoAction(@NonNull PendingIntent androidAutoReplyIntent, @NonNull PendingIntent androidAutoHeardIntent, long timestamp) { if (contentTitle == null || contentText == null) return; RemoteInput remoteInput = new RemoteInput.Builder(AndroidAutoReplyReceiver.VOICE_REPLY_KEY) .setLabel(context.getString(R.string.MessageNotifier_reply)) .build(); NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(contentTitle.toString()) .addMessage(contentText.toString()) .setLatestTimestamp(timestamp) .setReadPendingIntent(androidAutoHeardIntent) .setReplyAction(androidAutoReplyIntent, remoteInput); extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConversationBuilder.build())); }
Example #7
Source File: BigPictureSocialIntentService.java From android-Notifications with Apache License 2.0 | 5 votes |
private CharSequence getMessage(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(EXTRA_COMMENT); } return null; }
Example #8
Source File: WearableNotificationWithVoice.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Action buildWearableAction() { String replyLabel = mContext.getString(replyLabelResourceId); RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(replyLabel).build(); // Create an intent for the reply action if (pendingIntent == null) { Intent replyIntent = new Intent(mContext, notificationHandler); pendingIntent = PendingIntent.getActivity(mContext, (int) (System.currentTimeMillis() & 0xfffffff), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); } // Create the reply action and add the remote input NotificationCompat.Action action = new NotificationCompat.Action.Builder(actionIconResId, mContext.getString(actionTitleId), pendingIntent).addRemoteInput(remoteInput).build(); return action; }
Example #9
Source File: NotificationBroadcastReceiver.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 5 votes |
private CharSequence getMessageText(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(WearableNotificationWithVoice.EXTRA_VOICE_REPLY); } return null; }
Example #10
Source File: MessageReplyReceiver.java From MycroftCore-Android with Apache License 2.0 | 5 votes |
/** * Get the message text from the intent. * Note that you should call {@code RemoteInput#getResultsFromIntent(intent)} to process * the RemoteInput. */ private CharSequence getMessageText(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(MycroftMessagingService.EXTRA_VOICE_REPLY); } return null; }
Example #11
Source File: MessagingIntentService.java From android-Notifications with Apache License 2.0 | 5 votes |
private CharSequence getMessage(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(EXTRA_REPLY); } return null; }
Example #12
Source File: MessagingIntentService.java From android-Notifications with Apache License 2.0 | 5 votes |
private CharSequence getMessage(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(EXTRA_REPLY); } return null; }
Example #13
Source File: BigPictureSocialIntentService.java From android-Notifications with Apache License 2.0 | 5 votes |
private CharSequence getMessage(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(EXTRA_COMMENT); } return null; }
Example #14
Source File: NotificationBuilderImplBase.java From FCM-for-Mojo with GNU General Public License v3.0 | 5 votes |
/** * 创建通知的回复动作。 * * @param context Context * @param requestCode PendingIntent 的 requestId * @param chat 对应的 Chat * @return NotificationCompat.Action */ private static NotificationCompat.Action createReplyAction(Context context, int requestCode, Chat chat) { Intent intent = FFMBroadcastReceiver.replyIntent(chat); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); String replyLabel = context.getString(R.string.notification_action_reply, chat.getName()); RemoteInput remoteInput = new RemoteInput.Builder(NOTIFICATION_INPUT_KEY) .setLabel(replyLabel) .build(); return new NotificationCompat.Action.Builder(R.drawable.ic_reply_24dp, replyLabel, pendingIntent) .addRemoteInput(remoteInput) .build(); }
Example #15
Source File: SingleRecipientNotificationBuilder.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public void addActions(@NonNull PendingIntent markReadIntent, @NonNull PendingIntent quickReplyIntent, @NonNull PendingIntent wearableReplyIntent, @NonNull ReplyMethod replyMethod) { Action markAsReadAction = new Action(R.drawable.check, context.getString(R.string.MessageNotifier_mark_read), markReadIntent); String actionName = context.getString(R.string.MessageNotifier_reply); String label = context.getString(replyMethodLongDescription(replyMethod)); Action replyAction = new Action(R.drawable.ic_reply_white_36dp, actionName, quickReplyIntent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { replyAction = new Action.Builder(R.drawable.ic_reply_white_36dp, actionName, wearableReplyIntent) .addRemoteInput(new RemoteInput.Builder(DefaultMessageNotifier.EXTRA_REMOTE_REPLY) .setLabel(label).build()) .build(); } Action wearableReplyAction = new Action.Builder(R.drawable.ic_reply, actionName, wearableReplyIntent) .addRemoteInput(new RemoteInput.Builder(DefaultMessageNotifier.EXTRA_REMOTE_REPLY) .setLabel(label).build()) .build(); addAction(markAsReadAction); addAction(replyAction); extend(new NotificationCompat.WearableExtender().addAction(markAsReadAction) .addAction(wearableReplyAction)); }
Example #16
Source File: AndroidAutoReplyReceiver.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private CharSequence getMessageText(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(VOICE_REPLY_KEY); } return null; }
Example #17
Source File: MessagingIntentService.java From wear-os-samples with Apache License 2.0 | 5 votes |
private CharSequence getMessage(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(EXTRA_REPLY); } return null; }
Example #18
Source File: BigPictureSocialIntentService.java From user-interface-samples with Apache License 2.0 | 5 votes |
private CharSequence getMessage(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(EXTRA_COMMENT); } return null; }
Example #19
Source File: MessagingIntentService.java From user-interface-samples with Apache License 2.0 | 5 votes |
private CharSequence getMessage(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(EXTRA_REPLY); } return null; }
Example #20
Source File: BigPictureSocialIntentService.java From user-interface-samples with Apache License 2.0 | 5 votes |
private CharSequence getMessage(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(EXTRA_COMMENT); } return null; }
Example #21
Source File: MessagingIntentService.java From user-interface-samples with Apache License 2.0 | 5 votes |
private CharSequence getMessage(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(EXTRA_REPLY); } return null; }
Example #22
Source File: MyFirebaseMessagingService.java From NaviBee with GNU General Public License v3.0 | 5 votes |
public static CharSequence getReplyMessage(Intent intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(KEY_TEXT_REPLY); } return null; }
Example #23
Source File: FFMBroadcastReceiver.java From FCM-for-Mojo with GNU General Public License v3.0 | 5 votes |
@Override public void onReceive(final Context context, Intent intent) { if (intent == null || intent.getAction() == null) { return; } Chat chat = intent.getParcelableExtra(EXTRA_CHAT); switch (intent.getAction()) { case ACTION_REPLY: Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); handleReply(context, remoteInput, chat); break; case ACTION_CONTENT: handleContent(context, chat); break; case ACTION_DELETE: handleDelete(context, chat); break; case ACTION_OPEN_SCAN: handleOpenScan(context); break; case ACTION_DISMISS_SYSTEM_NOTIFICATION: handleDismissSystemNotification(context); break; case ACTION_COPY_TO_CLIPBOARD: String text = intent.getStringExtra(Intent.EXTRA_TEXT); handleCopyToClipBoard(context, text); break; } }
Example #24
Source File: QiscusPushNotificationUtil.java From qiscus-sdk-android with Apache License 2.0 | 4 votes |
private static void pushNotification(Context context, QiscusComment comment, QiscusPushNotificationMessage pushNotificationMessage, Bitmap largeIcon) { String notificationChannelId = Qiscus.getApps().getPackageName() + ".qiscus.sdk.notification.channel"; if (BuildVersionUtil.isOreoOrHigher()) { NotificationChannel notificationChannel = new NotificationChannel(notificationChannelId, "Chat", NotificationManager.IMPORTANCE_HIGH); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { notificationManager.createNotificationChannel(notificationChannel); } } PendingIntent pendingIntent; Intent openIntent = new Intent(context, QiscusPushNotificationClickReceiver.class); openIntent.putExtra("data", comment); pendingIntent = PendingIntent.getBroadcast(context, QiscusNumberUtil.convertToInt(comment.getRoomId()), openIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, notificationChannelId); notificationBuilder.setContentTitle(pushNotificationMessage.getRoomName()) .setContentIntent(pendingIntent) .setContentText(pushNotificationMessage.getMessage()) .setTicker(pushNotificationMessage.getMessage()) .setSmallIcon(Qiscus.getChatConfig().getNotificationSmallIcon()) .setLargeIcon(largeIcon) .setColor(ContextCompat.getColor(context, Qiscus.getChatConfig().getInlineReplyColor())) .setGroup("CHAT_NOTIF_" + comment.getRoomId()) .setAutoCancel(true) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); if (Qiscus.getChatConfig().isEnableReplyNotification() && isNougatOrHigher()) { String getRepliedTo = pushNotificationMessage.getRoomName(); RemoteInput remoteInput = new RemoteInput.Builder(KEY_NOTIFICATION_REPLY) .setLabel(QiscusTextUtil.getString(R.string.qiscus_reply_to, getRepliedTo.toUpperCase())) .build(); NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_send, QiscusTextUtil.getString(R.string.qiscus_reply_to, getRepliedTo.toUpperCase()), pendingIntent) .addRemoteInput(remoteInput) .build(); notificationBuilder.addAction(replyAction); } boolean cancel = false; if (Qiscus.getChatConfig().getNotificationBuilderInterceptor() != null) { cancel = !Qiscus.getChatConfig().getNotificationBuilderInterceptor() .intercept(notificationBuilder, comment); } if (cancel) { return; } NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); List<QiscusPushNotificationMessage> notifItems = QiscusCacheManager.getInstance() .getMessageNotifItems(comment.getRoomId()); if (notifItems == null) { notifItems = new ArrayList<>(); } int notifSize = 5; if (notifItems.size() < notifSize) { notifSize = notifItems.size(); } if (notifItems.size() > notifSize) { inboxStyle.addLine("......."); } int start = notifItems.size() - notifSize; for (int i = start; i < notifItems.size(); i++) { inboxStyle.addLine(notifItems.get(i).getMessage()); } inboxStyle.setSummaryText(QiscusTextUtil.getString(R.string.qiscus_notif_count, notifItems.size())); notificationBuilder.setStyle(inboxStyle); if (notifSize <= 3) { notificationBuilder.setPriority(Notification.PRIORITY_HIGH); } QiscusAndroidUtil.runOnUIThread(() -> NotificationManagerCompat.from(context) .notify(QiscusNumberUtil.convertToInt(comment.getRoomId()), notificationBuilder.build())); }
Example #25
Source File: BigPictureSocialIntentService.java From user-interface-samples with Apache License 2.0 | 4 votes |
private NotificationCompat.Builder recreateBuilderWithBigPictureStyle() { // Main steps for building a BIG_PICTURE_STYLE notification (for more detailed comments on // building this notification, check MainActivity.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(); // 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); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(BigPictureSocialMainActivity.class); stackBuilder.addNextIntent(mainIntent); PendingIntent mainPendingIntent = PendingIntent.getActivity( this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT ); // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification String replyLabel = getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT) .setLabel(replyLabel) .setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses()) .build(); PendingIntent replyActionPendingIntent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Intent intent = new Intent(this, BigPictureSocialIntentService.class); intent.setAction(BigPictureSocialIntentService.ACTION_COMMENT); replyActionPendingIntent = PendingIntent.getService(this, 0, intent, 0); } else { replyActionPendingIntent = mainPendingIntent; } NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent) .addRemoteInput(remoteInput) .build(); // 4. Build and issue the notification NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder(getApplicationContext()); GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); 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); // If the phone is in "Do not disturb mode, the user will still be notified if // the sender(s) is starred as a favorite. for (String name : bigPictureStyleSocialAppData.getParticipants()) { notificationCompatBuilder.addPerson(name); } return notificationCompatBuilder; }
Example #26
Source File: MycroftMessagingService.java From MycroftCore-Android with Apache License 2.0 | 4 votes |
private void sendNotification(int conversationId, String message, String participant, long timestamp) { // A pending Intent for reads PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId, createIntent(conversationId, READ_ACTION), PendingIntent.FLAG_UPDATE_CURRENT); // Build a RemoteInput for receiving voice input in a Car Notification RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel("Reply by voice") .build(); // Building a Pending Intent for the reply action to trigger PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId, createIntent(conversationId, REPLY_ACTION), PendingIntent.FLAG_UPDATE_CURRENT); // Create the UnreadConversation and populate it with the participant name, // read and reply intents. NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(participant) .setLatestTimestamp(timestamp) .setReadPendingIntent(readPendingIntent) .setReplyAction(replyIntent, remoteInput); NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()) // Set the application notification icon: //.setSmallIcon(R.drawable.notification_icon) // Set the large icon, for example a picture of the other recipient of the message //.setLargeIcon(personBitmap) .setContentText(message) .setWhen(timestamp) .setContentTitle(participant) .setContentIntent(readPendingIntent) .extend(new NotificationCompat.CarExtender() .setUnreadConversation(unreadConvBuilder.build())); mNotificationManager.notify(conversationId, builder.build()); }
Example #27
Source File: ServiceUI.java From FairEmail with GNU General Public License v3.0 | 4 votes |
private void onReplyDirect(long id, Intent intent) throws IOException { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean prefix_once = prefs.getBoolean("prefix_once", true); boolean plain_only = prefs.getBoolean("plain_only", false); Bundle results = RemoteInput.getResultsFromIntent(intent); String body = results.getString("text"); if (body != null) body = "<p>" + body.replaceAll("\\r?\\n", "<br>") + "</p>"; DB db = DB.getInstance(this); try { db.beginTransaction(); EntityMessage ref = db.message().getMessage(id); if (ref == null) throw new IllegalArgumentException("message not found"); EntityIdentity identity = db.identity().getIdentity(ref.identity); if (identity == null) throw new IllegalArgumentException("identity not found"); EntityFolder outbox = db.folder().getOutbox(); if (outbox == null) throw new IllegalArgumentException("outbox not found"); String subject = (ref.subject == null ? "" : ref.subject); if (prefix_once) { String re = getString(R.string.title_subject_reply, ""); subject = subject.replaceAll("(?i)" + Pattern.quote(re.trim()), "").trim(); } EntityMessage reply = new EntityMessage(); reply.account = identity.account; reply.folder = outbox.id; reply.identity = identity.id; reply.msgid = EntityMessage.generateMessageId(); reply.inreplyto = ref.msgid; reply.thread = ref.thread; reply.to = ref.from; reply.from = new Address[]{new InternetAddress(identity.email, identity.name)}; reply.subject = getString(R.string.title_subject_reply, subject); reply.received = new Date().getTime(); reply.seen = true; reply.ui_seen = true; reply.id = db.message().insertMessage(reply); File file = reply.getFile(this); Helper.writeText(file, body); db.message().setMessageContent(reply.id, true, HtmlHelper.getLanguage(this, body), plain_only || ref.plain_only, HtmlHelper.getPreview(body), null); EntityOperation.queue(this, reply, EntityOperation.SEND); db.setTransactionSuccessful(); } finally { db.endTransaction(); } ServiceSend.start(this); ToastEx.makeText(this, R.string.title_queued, Toast.LENGTH_LONG).show(); }
Example #28
Source File: BigPictureSocialIntentService.java From android-Notifications with Apache License 2.0 | 4 votes |
private NotificationCompat.Builder recreateBuilderWithBigPictureStyle() { // Main steps for building a BIG_PICTURE_STYLE notification (for more detailed comments on // building this notification, check MainActivity.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(); // 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); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(BigPictureSocialMainActivity.class); stackBuilder.addNextIntent(mainIntent); PendingIntent mainPendingIntent = PendingIntent.getActivity( this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT ); // 3. Set up RemoteInput, so users can input (keyboard and voice) from notification String replyLabel = getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(BigPictureSocialIntentService.EXTRA_COMMENT) .setLabel(replyLabel) .setChoices(bigPictureStyleSocialAppData.getPossiblePostResponses()) .build(); PendingIntent replyActionPendingIntent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Intent intent = new Intent(this, BigPictureSocialIntentService.class); intent.setAction(BigPictureSocialIntentService.ACTION_COMMENT); replyActionPendingIntent = PendingIntent.getService(this, 0, intent, 0); } else { replyActionPendingIntent = mainPendingIntent; } NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_white_18dp, replyLabel, replyActionPendingIntent) .addRemoteInput(remoteInput) .build(); // 4. Build and issue the notification NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder(getApplicationContext()); GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); 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); // If the phone is in "Do not disturb mode, the user will still be notified if // the sender(s) is starred as a favorite. for (String name : bigPictureStyleSocialAppData.getParticipants()) { notificationCompatBuilder.addPerson(name); } return notificationCompatBuilder; }
Example #29
Source File: WearReplyReceiver.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { ApplicationLoader.postInitApplication(); Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput == null) { return; } CharSequence text = remoteInput.getCharSequence(NotificationsController.EXTRA_VOICE_REPLY); if (TextUtils.isEmpty(text)) { return; } long dialog_id = intent.getLongExtra("dialog_id", 0); int max_id = intent.getIntExtra("max_id", 0); int currentAccount = intent.getIntExtra("currentAccount", 0); if (dialog_id == 0 || max_id == 0) { return; } int lowerId = (int) dialog_id; int highId = (int) (dialog_id >> 32); AccountInstance accountInstance = AccountInstance.getInstance(currentAccount); if (lowerId > 0) { TLRPC.User user = accountInstance.getMessagesController().getUser(lowerId); if (user == null) { Utilities.globalQueue.postRunnable(() -> { TLRPC.User user1 = accountInstance.getMessagesStorage().getUserSync(lowerId); AndroidUtilities.runOnUIThread(() -> { accountInstance.getMessagesController().putUser(user1, true); sendMessage(accountInstance, text, dialog_id, max_id); }); }); return; } } else if (lowerId < 0) { TLRPC.Chat chat = accountInstance.getMessagesController().getChat(-lowerId); if (chat == null) { Utilities.globalQueue.postRunnable(() -> { TLRPC.Chat chat1 = accountInstance.getMessagesStorage().getChatSync(-lowerId); AndroidUtilities.runOnUIThread(() -> { accountInstance.getMessagesController().putChat(chat1, true); sendMessage(accountInstance, text, dialog_id, max_id); }); }); return; } } sendMessage(accountInstance, text, dialog_id, max_id); }
Example #30
Source File: MainActivity.java From wearable with Apache License 2.0 | 4 votes |
/** * This adds the voice response for the wearable device. * It comes back via an intent, which is shown in voiceNotiActivity. */ void voiceReplytNoti() { //create the intent to launch the notiactivity, then the pentingintent. Intent replyIntent = new Intent(this, VoiceNotiActivity.class); replyIntent.putExtra("NotiID", "Notification ID is " + notificationID); PendingIntent replyPendingIntent = PendingIntent.getActivity(this, 0, replyIntent, 0); // create the remote input part for the notification. RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel("Reply") .build(); // Create the reply action and add the remote input NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_action_map, "Reply", replyPendingIntent) .addRemoteInput(remoteInput) .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("reply Noti") .setContentText("voice reply example.") .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++; }