How can I send message to specific contact through WhatsApp from my android app?

前端 未结 13 1599
梦毁少年i
梦毁少年i 2020-12-02 17:41

I am developing an android app and I need to send a message to specific contact from WhatsApp. I tried this code:

Uri mUri = Uri.parse(\"smsto:+999999999\");         


        
13条回答
  •  孤街浪徒
    2020-12-02 18:34

    This is what works for me.

    The parameter 'body' gets not red by the whatsapp app, use 'Intent.EXTRA_TEXT' instead.

    By setting the 'phoneNumber' you specify the contact to open in whatsapp.

    Intent sendIntent = new Intent(Intent.ACTION_SENDTO, 
           Uri.parse("smsto:" + "" + phoneNumber + "?body=" + encodedMessage));
    sendIntent.putExtra(Intent.EXTRA_TEXT, message);
    sendIntent.setPackage("com.whatsapp");
    startActivity(sendIntent);
    

提交回复
热议问题