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

前端 未结 13 1526
梦毁少年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:41

    There is a way. Make sure that the contact you are providing must be passed as a string in intent without the prefix "+". Country code should be appended as a prefix to the phone number .

    e.g.: '+918547264285' should be passed as '918547264285' . Here '91' in beginning is country code .

    Note :Replace the 'YOUR_PHONE_NUMBER' with contact to which you want to send the message.

    Here is the snippet :

     Intent sendIntent = new Intent("android.intent.action.MAIN");
     sendIntent.setComponent(new  ComponentName("com.whatsapp","com.whatsapp.Conversation"));
     sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("YOUR_PHONE_NUMBER")+"@s.whatsapp.net");
     startActivity(sendIntent);
    
    0 讨论(0)
提交回复
热议问题