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=horizontstack.autoreplyforwhatsapp.whatsreply
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.
I did by this:
Step 1: copy all code from NotificationHelperLibrary repository.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With