Automatic reply for whatsapp messages approach

心不动则不痛 提交于 2019-12-01 12:55:22

I did by this:
Step 1: copy all code from repository: https://github.com/iamrobj/NotificationHelperLibrary Step 2: Create Notification Listener Service and put below code in onNotificationPosted(..) method:

MyNotifiService.this.cancelNotification(sbn.getKey());

        Action action = NotificationUtils.getQuickReplyAction(sbn.getNotification(), getPackageName());

        if (action != null) {
            Log.i(TAG, "success");
            try {
                action.sendReply(getApplicationContext(), "Hello");
            } catch (PendingIntent.CanceledException e) {
                Log.i(TAG, "CRAP " + e.toString());
            }
        } else {
            Log.i(TAG, "not success");
        }

This is a basic demo. https://github.com/salmankhalid8762/WhatsAppAutoReply3

In newer versions of WhatsApp and Android OS, you can reply directly from the notification, this is how the apps are doing that. Probably nothing to do with the code you posted. So, if you want to implement auto-reply, you must deal with the notification, and keep in mind the Android OS version limitation

EDIT: Check this post to read notifications using accesibility services

Whatsapp messages contain the Car Extension. You can use it to get the corresponding PendingIntent that you will need to reply to the message.

Bundle extension = NotificationCompat.getExtras(notification).getBundle("android.car.EXTENSIONS");
Bundle conversation = extension.getBundle("car_conversation");
PendingIntent reply = conversation.getParcelable("on_reply");

In newer version(>= Android 7 ), we have the ability to reply to notification directly from notificationlistener(i have tested it works for all messaging app with multiple messages from user)

This link will be useful for this=> link

For earlier version, we can get action for notification from wearable notification. See this for more info :- link

Source code for above post :- link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!