简体   繁体   English

直接从我的 android 应用程序发送 whatsapp 消息

[英]Send whatsapp message directly from my android app

In my android application after user fill textbox of mobile no and message which he wants to send to that mobile number and click send button, that message should be sent to that mobile number directly without making the user to click send button in WhatsApp app.在我的 android 应用程序中,用户填写手机号码的文本框和他想要发送到该手机号码的消息并单击发送按钮后,该消息应直接发送到该手机号码,而无需让用户单击 WhatsApp 应用程序中的发送按钮。 在此处输入图片说明

Below is the code I am using for sending WhatsApp message.以下是我用于发送 WhatsApp 消息的代码。

Uri mUri = Uri.parse("https://api.whatsapp.com/send?phone=9197xxxxxx88&text='Hello User'");
Intent intent = new Intent("android.intent.action.VIEW", mUri);
intent.setPackage("com.whatsapp");
startActivity(intent);

我相信您正在寻找一个 What app API,它将为您完成发送部分。AFAIK Whats app 没有为类似目的公开此类 API。

WhatApp is not providing any API that will do the sending part for you. WhatApp 不提供任何 API 来为您完成发送部分。

You can try with below code:您可以尝试使用以下代码:

                var toNumber = "+91 xxxxx xxxxx" // contains spaces.
                toNumber = toNumber.replace("+", "").replace(" ", "")

                val sendIntent = Intent("android.intent.action.MAIN")
                sendIntent.putExtra("jid", "$toNumber@s.whatsapp.net")
                sendIntent.putExtra(Intent.EXTRA_TEXT, "Hello")
                sendIntent.action = Intent.ACTION_SEND
                sendIntent.setPackage("com.whatsapp")
                sendIntent.type = "text/plain"
                startActivity(sendIntent)

I hope It will help you..我希望它会帮助你..

You can do that by using accessibility in android您可以通过在 android 中使用辅助功能来做到这一点

Here you can find example like what you want Send message via whatsapp programmatically在这里您可以找到类似您想要的示例以编程方式通过 whatsapp 发送消息

Below code can be used to send a predefined text to a specific number.下面的代码可用于将预定义的文本发送到特定号码。 It will open IB of that number.它将打开该号码的IB。 However, it can't automatically send for you.但是,它无法自动为您发送。

 startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse(
"https://api.whatsapp.com/send?phone=+91xxxxxxxxxx&text=Hey%20there% )));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM