0down votefavorite 
<http://stackoverflow.com/questions/40604694/android-n-inline-reply-issue-for-priority-message#>

I observed one issue while doing inline reply for priority messages. If you 
reply directly when your notification is being displayed on other app or on 
home screen. The reply works perfectly but it does not remove the 
notification from status bar and notification panel.

And the same issue is with WhatsApp as well.

I have gone through Google Developer Doc 
<https://developer.android.com/guide/topics/ui/notifiers/notifications.html>
 and Android Developer Blog 
<http://android-developers.blogspot.in/2016/06/notifications-in-android-n.html> 
but 
could not figure out the resolution.

Here are the testing videos :

   - WhatsApp Notification Testing <http://sendvid.com/se8sn97r//>
   - My App Link <http://sendvid.com/jhukd0w0>


*Notification Code*

 /**
 * Create chat message reply ui
 *
 * @param singleUserMessage
 * @param context
 * @param channelId
 * @param RecipientUserId
 * @param builder
 */private void setDirectChatReply(boolean singleUserMessage, Context context, 
String channelId, String RecipientUserId, NotificationCompat.Builder builder) {
    if (singleUserMessage && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        // Key for the string that's delivered in the action's intent.
        RemoteInput remoteInput = new 
RemoteInput.Builder(Constants.GCM.DIRECT_REPLY_KEY)
                .setLabel(getString(R.string.direct_reply_notif_label))
                .build();
        // Create the reply action and add the remote input.
        Intent broadcastIntent = new Intent(context, 
ReplyBroadcastReceiver.class);
        broadcastIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 
Intent.FLAG_ACTIVITY_CLEAR_TASK);
        broadcastIntent.putExtra(Constants.Conversations.CHANNEL_ID, channelId);
        broadcastIntent.putExtra(Constants.Conversations.RECIPIENT_USER_ID, 
RecipientUserId);
        broadcastIntent.putExtra(Constants.Conversations.CHAT_USER_ID, 
mDesidimeSharedPreferences.getMyChatUserId());
        PendingIntent replyIntent = PendingIntent.getBroadcast(context, 
Constants.NotificationValues.CHAT_NOTIFICATION_ID,
                broadcastIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Action action = new 
NotificationCompat.Action.Builder(R.drawable.ic_send,
                getString(R.string.notif_action_reply), 
replyIntent).addRemoteInput(remoteInput).build();
        builder.addAction(action);
    }}

*DirectReply class to handle inline replies*

    public class ReplyBroadcastReceiver extends BroadcastReceiver implements 
MessageSenderTask.ChatMessageProcessor {
    private static final String TAG = "ReplyBroadcastReceiver";
    private Context mContext;

    @Override
    public void onReceive(Context context, Intent intent) {
        mContext = context;
        // Hit Analytics
        DesidimeSharedPreferences sharedPreferences = new 
DesidimeSharedPreferences(context);
        Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
        if (remoteInput != null) {
            String reply = 
remoteInput.getString(Constants.GCM.DIRECT_REPLY_KEY);
            if (!TextUtils.isEmpty(reply)) {
                Bundle dataBundle = intent.getExtras();
                dataBundle.putString(Constants.Conversations.MESSAGE_KEY, 
reply);
                dataBundle.putString(Constants.Conversations.MESSAGE_TYPE, 
Constants.Conversations.MESSGE_TYPE_CHAT);
                MessageSenderTask messageSenderTask = new 
MessageSenderTask(context, this);
                messageSenderTask.setMessageData(dataBundle, 
sharedPreferences.getUserId());
                messageSenderTask.execute();
            }

        }
    }

    @Override
    public void onMessageProcessed(Bundle data) {
        if (data != null) {
            NotificationManager manager = (NotificationManager) 
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
            manager.cancel(Constants.NotificationValues.CHAT_NOTIFICATION_ID);
            
updateUnreadConversationStatus(data.getString(Constants.Conversations.RECIPIENT_USER_ID));
        }


    }

    /**
     * Locally manage read/unread conversation for Recent user list
     * @param recipientId
     */
    private void updateUnreadConversationStatus(String recipientId) {
        try {
            if (StringUtils.isNotEmpty(recipientId)) {
                ChatManager chatManager = new 
ChatManager(DBTables.Conversations.TABLE_RECENT_USER_LIST, mContext);
                chatManager.updateConversationUnreadStatus(recipientId);
            }
        } catch (Exception e) {
            Crashlytics.log(Log.DEBUG, TAG, "updateUnreadConversationStatus 
recipientId : "+recipientId);
            Crashlytics.logException(e);
        }
    }

    @Override
    public void onMessageProcessedFailed() {
        Log.d(TAG, "onMessageProcessedFailed");
    }}

*Here on onMessageProcessed , I am removing the notification from 
notification panel.*

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/b27ac875-d48f-4b5b-adfb-69e80dc530ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to