Android: How to send message programmatically by using WhatsApp, WeChat?

前端 未结 5 1559
情歌与酒
情歌与酒 2020-12-02 17:58

How to use messaging in android application by using WhatsApp and WeChat?

Actually requirement is to send sms using WhatsApp and We

5条回答
  •  心在旅途
    2020-12-02 18:21

    To send direct message to any whatsapp user use following code :

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

提交回复
热议问题