java - Whatsapp 自动发送消息而无需单击 android 上的发送按钮
问题描述
我已经在互联网上搜索了很长时间,但仍然找不到自动发送消息的方法。到目前为止,我的应用程序可以做的是向某个联系人打开 Whatsapp 并写下我要发送的消息。这是我的代码:
此代码用于检查设备上是否安装了 Whatsapp
private boolean checkWA(String uri) {
PackageManager packageManager = getPackageManager();
boolean appInstalled;
try {
packageManager.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
appInstalled = true;
}
catch (PackageManager.NameNotFoundException e) {
appInstalled = false;
}
return appInstalled;
}
此代码旨在 Whatsapp(无法自动发送消息)
public void onClickWhatsApp() {
boolean installed = checkWA("com.whatsapp");
if (installed){
String url = "https://api.whatsapp.com/send/?phone=6282167975500&text=" + "ADDON ERROR";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setPackage("com.whatsapp");
i.setData(Uri.parse(url));
startActivity(i);
}
else {
String url = "https://api.whatsapp.com/send/?phone=6282167975500&text=" + "ADDON ERROR";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
}
有谁知道如何做自动发送部分?谢谢。
解决方案
推荐阅读
- ios - Xamarin 应用程序无法在 iOS <= 10 上启动:“无法使用 bundleID 引导进程...”
- c++ - 使用 TensorFlow C API 获取张量的 top-K 值
- java - Java UI 布局选择
- parsing - 如何在 htmlagalitypack 中转义 /n/t/t/t
- bazel - 如何使用 Bazel 正确处理测试覆盖率报告 (HTML) 生成?
- python - 用 pip 安装 kivy
- c# - 在运行时使用反射调用泛型方法
- azure - 管道运行 - 按工厂查询不适用于 Webhook
- php - 在php中第一个逗号后删除字符不起作用
- reactjs - React Data Grid - 添加具有多个表的自定义复制粘贴功能