我在网上搜索了很长一段时间,仍然找不到自动发送信息的方法。到目前为止,我的应用程序能做的就是打开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);
}
}
有人知道怎么做自动发送部分吗?谢谢。
暂无答案!
目前还没有任何答案,快来回答吧!