Sending message through WhatsApp

前端 未结 23 2503
萌比男神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:17

    Tested on Marshmallow S5 and it works!

        Uri uri = Uri.parse("smsto:" + "phone number with country code");
        Intent sendIntent = new Intent(Intent.ACTION_SENDTO, uri);
        sendIntent.setPackage("com.whatsapp");
        startActivity(sendIntent); 
    

    This will open a direct chat with a person, if whatsapp not installed this will throw exception, if phone number not known to whatsapp they will offer to send invite via sms or simple sms message

提交回复
热议问题