尝试了堆栈溢出的一切,现在我能够采取的msg frwd。但是,直到您实际单击“否”,才会发送msg。WhatsApp联系人列表请帮助被困在这里几天....事情是,我试图建立一个应用程序,在其中,当我给予一个数字,然后味精应该发送到它使用WhatsApp。使用此代码从Satheesh's answer here msg正在frwded,当我选择一个号码,它发送预定义的msg给它。但我希望该味精应直接发送没有什么应用程序等待用户点击一个数字。.
//checks if whats app is installed or not..
private boolean whatsappInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
//Main Process
boolean isWhatsappInstalled = whatsappInstalledOrNot("com.whatsapp");
if (isWhatsappInstalled) {
String a="91*********0";// the nuber to which msg is to be sent
Uri uri = Uri.parse("smsto:" + a);
Intent sendIntent = new Intent(Intent.ACTION_SEND, uri);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Test message"+a);//msg to be sent
//sendIntent.putExtra("sms_body", "ydyeryyerf");
sendIntent.setType("text/plain");// type of msg->text
sendIntent.putExtra("chat",true);
sendIntent.setPackage("com.whatsapp");// picks whats app
// startActivity(sendIntent);
startActivity(Intent.createChooser(sendIntent, a));//starts whats app
} else {
// should redriect to play store to download whatsApp
Toast.makeText(getApplicationContext(), "WhatsApp not Installed",
Toast.LENGTH_SHORT).show();
Uri uri = Uri.parse("market://details?id=com.whatsapp");
Intent playStore = new Intent(Intent.ACTION_VIEW, uri);
startActivity(playStore);
}
2条答案
按热度按时间nwnhqdif1#
不使用
Uri uri = Uri.parse("smsto:" + a);
,而使用sendIntent.putExtra("jid", + number + "@s.whatsapp.net")
“number”应该是没有前导+的实际数字wvt8vs2t2#
简短回答:这是不可能的。除非你为whatsapp API构建自己的实现,否则你无法做到这一点,在这种情况下,你将需要发件人电话号码和密码,而这无法务实地完成。具体步骤如下:1 -把根移动的电话,并把发送者SIM卡2 -获取WhatsApp存储密码的文件,并获得密码3 -实现WhatsApp迷你客户端,使用此用户名和密码,发送您的消息.