Send Whatsapp message to specific contact

前端 未结 8 2115
南旧
南旧 2020-12-05 05:27

I followed this link and this is my code

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(\"content://com.android.contacts/data/\" + \"MYNUMBER@s.whatsapp         


        
8条回答
  •  情深已故
    2020-12-05 06:18

    I found the right way to do this and is just simple after you read this article: http://howdygeeks.com/send-whatsapp-message-unsaved-number-android/

    phone and message are both String.

    Source code:

    try {
                PackageManager packageManager = context.getPackageManager();
                Intent i = new Intent(Intent.ACTION_VIEW);
                String url = "https://api.whatsapp.com/send?phone="+ phone +"&text=" + URLEncoder.encode(message, "UTF-8");
                i.setPackage("com.whatsapp");
                i.setData(Uri.parse(url));
                if (i.resolveActivity(packageManager) != null) {
                    context.startActivity(i);
                }
            } catch (Exception e){
                e.printStackTrace();
            }
    

    Enjoy!

提交回复
热议问题