API for Android to interact with WhatsApp

The initial idea is to connect or have an application Android so that it can interact with WhatsApp (e.g. send text to WhatsApp, enable or disable features for a given user ect).

I have searched for some API for this task but I have not been able to find any, and the one I found may be abandoned ( https://github.com/venomous0x/WhatsAPI ) and is unofficial.

Is there any official API for it?.

On the other hand the alternative I am using is the following (for text sending):

After looking at this link (in English)

Intent sendIntent = new Intent();

sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");

startActivity(sendIntent);

More or less would be something like this:

public void enviarMsgApp(View view) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent .setType("text/plain");
    String texto = "Mensaje para enviar aqui";
    intent .setPackage("com.whatsapp");
    if (intent != null) {
        intent .putExtra(Intent.EXTRA_TEXT, texto);
        startActivity(Intent.createChooser(intent, texto));
    } else {
        Toast.makeText(this,"Nooo whatsapp, whatsapp man",  
                       Toast.LENGTH_SHORT)
                       .show();
    }
}

There is an alternative to be able to modify the" behavior " of WhatsApp on a user.

For example something like telling the application (that is being created) the name of the user, and this application can make the changes about that user. for example change the photo displayed, mute etc, even if for this you have to request permissions from the user or that the same WhatsApp alerts the user that it is trying to make an adjustment and he has to authorize it or something like that.

Pseudo code:

public void cambiarFotoApp(View view, String nombreUsuario) {
        //..    
        Intent intent = new Intent(Intent.ACTION_SEND);
        //..

        intent .setPackage("com.whatsapp"); 
        //..
        //cambiarFoto(nombreUsuario, jpgNuevaFoto); 
}
 11
Author: Angel Angel, 2016-01-11

4 answers

At the moment there is no official API to interact with the application beyond the example you show to send a message.

For a while a viable option was WhatsAPI but the author had legal problems for this repository and abandoned development.

 7
Author: enrique7mc, 2016-01-11 18:01:14

The best solution you can use is through the link:

"whatsapp: / / send?phone=59165868685 & text = This is the message to change "

        Intent intent = new Intent(Intent.ACTION_VIEW);
        String uri = "whatsapp://send?phone=" + "codigo pais + tu numero ej: 59165868685" + "&text=" + "Este es el mensaje para enviar";
        intent.setData(Uri.parse(uri));
        startActivity(intent);

Greetings.

 1
Author: Jonathan JOhx, 2018-01-05 23:15:26

You could also use the following URL that allows you to open the app directly to send to the target phone number:

https://api.whatsapp.com/send?phone=59177242524

The country Code must be included in the number.

  • 591 country code
  • 77242524 phone number

Could be very useful for example when you are creating a contact screen in the application and with a "Contact Me" button open WhatsApp direct to write.

 0
Author: Daniel Alvarez, 2017-02-24 21:42:07

You could do this in a certain way using an accessibility service on Android but you would have to have the official application installed, I can not explain it further because my answer would be mega long so I suggest you enter the Accessibility section of Android developers.
Basically the principle would be based on extracting information from the notifications using the Accessibility Service in addition to interacting with explicit intents directly with the WhatsApp app

 0
Author: Paris N. Salguero, 2017-02-24 22:10:58