8

How I can send massage from my app to Special number in whatsapp , I know this code to share massage to group or contact on whatsapp

Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "Sorry For Interruption,I'm Just Trying Something";
waIntent.setPackage("com.whatsapp");

if (waIntent != null) {
    waIntent.putExtra(Intent.EXTRA_TEXT, text);//
    startActivity(Intent.createChooser(waIntent,"Share with"));

but I want send massage to Special number like "966xxxxxxx" how I can do that ?

Ahmad
  • 69,608
  • 17
  • 111
  • 137
Abdullah AlHazmy
  • 1,299
  • 1
  • 13
  • 22
  • There's no way to do that unless whatsapp have the ability to do so. – Alamri Jul 21 '13 at 03:23
  • You need whatsapp to understand extra fields in your intent. So if whatsapp can't do this, you have no way to achieve your goal. Try to search for documentation about whatsapp BroadcastReveivers and how Intents are parsed. – type-a1pha Jul 21 '13 at 04:33
  • Thank you , I found Solution :) – Abdullah AlHazmy Jul 23 '13 at 01:39
  • possible duplicate of [Sending message through WhatsApp](http://stackoverflow.com/questions/15462874/sending-message-through-whatsapp) – rds Oct 06 '13 at 17:08

2 Answers2

5

this is a Solution :

private void openWhatsApp(String id) {

Cursor c = getSherlockActivity().getContentResolver()
            .query(ContactsContract.Data.CONTENT_URI,
                  new String[] { ContactsContract.Contacts.Data._ID },  
                  ContactsContract.Data.DATA1 + "=?",
                  new String[] { id }, 
                  null);

c.moveToFirst();
Intent i = new Intent(Intent.ACTION_VIEW, 
              Uri.parse(
                   "content://com.android.contacts/data/" +           
                    c.getString(0)));

startActivity(i);
c.close();
}

Where id is what's app uri like 966123456789@s.whatsapp.net

Angel Koh
  • 12,479
  • 7
  • 64
  • 91
Abdullah AlHazmy
  • 1,299
  • 1
  • 13
  • 22
0

you can use this code for sending data to perticuler a 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, ""));}

thats realy works for me enjoy your code:)

John smith
  • 1,781
  • 17
  • 27