Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

android - Automatic reply for whatsapp messages approach

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...