-4

I collect 3 pieces of information: name, address, product.

I want to send them to a specific whatsapp number, the number is always the same, i d like to send data preferably to a chat inside whatsapp.

TextView name = (TextView)findViewById(R.id.name);
TextView address = (TextView)findViewById(R.id.address);
TextView product = (TextView)findViewById(R.id.product);

The whatsapp FAQ on the website gives this code:

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

sendIntent.setPackage("com.whatsapp");

Where is the place to specify a number that data should go to?

I want the order data to go right into a specific chat to a specific phone number like +77056748392.

Not just opening whatsapp for sharing! I suspect Whatsapp API does not have this functionality?

ERJAN
  • 23,696
  • 23
  • 72
  • 146

1 Answers1

1

You need to format by yourself.

String sendString = "Name: " + name + "\nAddress: " + address + "\nProduct: " + product; 
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, sendString);
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);

Now the message will be like:

Name : Erwin
Address: LA-36, USA
Product: T-shirt

If you want to open whatsapp with specific number you can do this :

Uri uri = Uri.parse("smsto:" + phoneNumber);
                Intent i = new Intent(Intent.ACTION_SENDTO, uri);
                i.setPackage("com.whatsapp");

But no idea how to send data in second option :)

Neo
  • 3,546
  • 1
  • 24
  • 31
  • thx, but this will not send message directly to a whatsapp number right? this will only OPEN whatsapp for sharing? i want it to go right to a specified chat to a specific number – ERJAN Jun 13 '16 at 10:23