1

I want to set a text as a description or your status like "available" in Whatsapp . I use Intent but it opens a selection page in Whatsapp if I want to share this text through story or send it to someone . That's because ACTION_SEND. Is there some type of action or any solution for my problem ?

Here is my code

Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
            whatsappIntent.setType("text/plain");
            whatsappIntent.setPackage("com.whatsapp");
            whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ahmed
  • 259
  • 3
  • 14

1 Answers1

1

According to WhatsApp FAQ

There are two ways to integrate with WhatsApp:

-Through a custom URL scheme

-Through Android's intent system.

Custom URL Scheme

If you want to open a WhatsApp chat with a pre-filled message, you can use our custom URL scheme to do so. Opening whatsapp://send?text= followed by the text to send, will open WhatsApp, allow the user to choose a contact, and pre-fill the input field with the specified text.

Example

https://api.whatsapp.com/send?phone=15551234567&text=I%27m%20interested%20in%20your%20car%20for%20sale

Android intent system

Like most social apps on Android, WhatsApp listens to intents to share media and text. Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker:

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

OR

With this code you can open the whatsapp chat with the given number.

 void openWhatsappContact(String number) {
    Uri uri = Uri.parse("smsto:" + number);
    Intent i = new Intent(Intent.ACTION_SENDTO, uri);
    i.setPackage("com.whatsapp");  
    startActivity(Intent.createChooser(i, ""));
}

You cannot set user status programmatically.

You can also see these for some more details:

  1. One
  2. Two
nimi0112
  • 2,065
  • 1
  • 18
  • 32
  • Thank you for your answer , but when I use `Intent` It doesn't show me the about page in whatsApp . How can I even show the about page ? I can't reach it when I use `Intent` – Ahmed May 20 '18 at 13:08
  • @Ahmed You can only send a prefilled text with an optional specific mobile number. Whats app does not provide any other api's. – nimi0112 May 20 '18 at 15:30
  • Aha .. Is there any way to do that ? to edit the "about" like (available or something else ) in user'sWhatsApp ? – Ahmed May 20 '18 at 18:48
  • @Ahmed: No WhatsApp does not allow to do this. Do you have any other queries if not please accept this answer. – nimi0112 May 21 '18 at 04:02
  • I can't vote up it because my reputation is less than 15 . – Ahmed May 21 '18 at 12:46
  • @Ahmed: MArk the answer as accepted then with a upvote :P. – nimi0112 May 21 '18 at 12:49