How can I open WhatsApp's conversation activity using contact data?

后端 未结 5 1287
我寻月下人不归
我寻月下人不归 2020-12-09 22:57

I want open what\'s app conversation activity cmp=com.whatsapp/.Conversation from my app.

How can I do this? I have contact phone number, contact id, c

相关标签:
5条回答
  • 2020-12-09 23:24

    You can use this example

    startActivity(new Intent(Intent.ACTION_VIEW,
                                Uri.parse(
                                        "https://api.whatsapp.com/send?phone=+628119xxx&text=I'm%20interested%20in%20your%20car%20for%20sale"
                                )));
    
    0 讨论(0)
  • 2020-12-09 23:25

    try this code :

    String smsNumber="919426640584@s.whatsapp.net";
    Uri uri = Uri.parse("smsto:" + smsNumber);
    Intent i = new Intent(Intent.ACTION_SENDTO, uri);
    i.putExtra("sms_body", "Prakash Gajera");
    i.setPackage("com.whatsapp");
    startActivity(i);
    
    0 讨论(0)
  • 2020-12-09 23:27

    My final solution when the contact number is unknown to the user.

    Optionally you can set a preformatted text also.

        try {
            String whatsAppRoot = "http://api.whatsapp.com/";
            String number = "send?phone=+xxxxxxxxxxx"; //here the mobile number with its international prefix
            String text = "&text=HERE YOUR TEXT";
            String uri = whatsAppRoot+number+text;
    
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(uri));
            startActivity(intent);
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), 
            "WhatsApp cannot be opened", Toast.LENGTH_SHORT).show();
        }
    
    0 讨论(0)
  • 2020-12-09 23:38
    private void openWhatsApp(String id) {
    
    Cursor c = 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 0987654321@s.whatsapp.net

    0 讨论(0)
  • 2020-12-09 23:47
     String KEY_QUICK_REPLY_TEXT = "Dear Valued Customer Thank you for contacting us your reference Number is "+refernceNumber ;
       Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setData(Uri.parse("http://api.whatsapp.com/send?phone="+phone +"&text="+KEY_QUICK_REPLY_TEXT));
                                startActivity(intent);
    
    Toast.makeText(MainActivity.this, response, Toast.LENGTH_SHORT).show();
    
    0 讨论(0)
提交回复
热议问题