下面是我用于通过android应用将消息发送到WhatsApp号的代码
PackageManager packageManager = this.getPackageManager();
Intent i = new Intent(Intent.ACTION_VIEW);
try {
String phone="+919999999999";
String url = "https://api.whatsapp.com/send?phone="+ phone +"&text=" + URLEncoder.encode("hello", "UTF-8");
i.setPackage("com.whatsapp");
i.setData(Uri.parse(url));
if (i.resolveActivity(packageManager) != null) {
this.startActivity(i);
}
}
catch (Exception e){
Toast.makeText(HomeActivity.this,e.getMessage(),Toast.LENGTH_LONG).show();
}
在应用程序的调试版本中运行正常,但在发行版本中则无法运行。按下发送按钮后没有任何反应,也没有显示异常。