我正在寻找向特定联系人发送whatsapp消息并尝试此代码 但它不适合我 代码打开特定联系但它不发送消息
String message="at first";
try {
Uri uri = Uri.parse("smsto:"+"+999999999");
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, uri);
//sendIntent.setAction(Intent.ACTION_SEND);
//sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
//sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
if sendIntent!= null) {
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
startActivity(sendIntent);
}else{
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT).show();
}
message="done";
}catch(Exception ex){
message="Error: "+ex.toString();
}finally{
TextView mas = (TextView) findViewById(R.id.mas);
mas.setText(message);
}