Automatic reply for whatsapp messages approach

2019-02-21 00:44发布

问题:

I have seen few applications on play store that supports automatic reply for WhatsApp, I searched the internet to find out the approach, but all I found was this piece of code

    Uri uri = Uri.parse("smsto:" + "99********");
    Intent i = new Intent(Intent.ACTION_SENDTO, uri);
    i.putExtra("sms_body", "Hey!");
    i.setPackage("com.whatsapp");
    startActivity(i);

It will open the WhatsApp and take you to that particular contact if you have saved and it will paste the given text but it will not send the message.

links

https://play.google.com/store/apps/details?id=tkstudio.wachatbotlite&hl=en https://play.google.com/store/apps/details?id=androidpills.com.whattoreply&hl=en

They are accessing the notifications to get the messages. I want to know how they are sending the messages in the background without opening the application. If somebody knows the approach please share here.

回答1:

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



回答2:

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");


回答3:

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