因为我发现了一些更老的帖子,说WhatsApp不支持这一点,我想知道是否有什么事情发生了变化,是否有办法打开WhatsApp与我通过意向发送的号码的"聊天"?
因为我发现了一些更老的帖子,说WhatsApp不支持这一点,我想知道是否有什么事情发生了变化,是否有办法打开WhatsApp与我通过意向发送的号码的"聊天"?
UPDATE
WhatsApp的点击聊天功能允许你开始与
示例:https://wa.me/15551234567?text=I'm%20interested%20in%20your%20car%20for%20sale
Original answer
public void onClickWhatsApp(View view) {
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}