Sending message through WhatsApp

前端 未结 23 2636
萌比男神i
萌比男神i 2020-11-22 09:42

Since I found some older posts, that tell that whatsapp doesn\'t support this, I was wondering if something had changed and if there is a way to open a whatsapp \'chat\' wit

23条回答
  •  情书的邮戳
    2020-11-22 10:26

    I found the following solution, first you'll need the whatsapp id:

    Matching with reports from some other threads here and in other forums the login name I found was some sort of: international area code without the 0's or + in the beginning + phone number without the first 0 + @s.whatsapp.net

    For example if you live in the Netherlands and having the phone number 0612325032 it would be 31612325023@s.whatsapp.net -> +31 for the Netherlands without the 0's or + and the phone number without the 0.

    public void sendWhatsAppMessageTo(String whatsappid) {
    
    Cursor c = getSherlockActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
            new String[] { ContactsContract.Contacts.Data._ID }, ContactsContract.Data.DATA1 + "=?",
            new String[] { whatsappid }, null);
    c.moveToFirst();
    
    Intent whatsapp = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
    c.close();
    
     if (whatsapp != null) {
    
    startActivity(whatsapp);      
    
    } else {
            Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
                    .show();
    //download for example after dialog
                    Uri uri = Uri.parse("market://details?id=com.whatsapp");
                    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
        }
    
    }
    

提交回复
热议问题