我正在开发一个Android应用程序,我需要向WhatsApp的特定联系人发送消息。代码在Android 4.4版本中无效。我试过这段代码:
void openWhatsappContact(String number) {
Uri uri = Uri.parse("smsto:" + number);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
}
答案 0 :(得分:0)
试试这段代码:
private void openWhatsApp(String id) {
Cursor c =
getSherlockActivity().getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
new String[] { ContactsContract.Contacts.Data._ID },
ContactsContract.Data.DATA1 + "=?",
new String[] { id }, null);
c.moveToFirst();
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
startActivity(i);
c.close();
}
id是什么样的应用程序?
0987654321@s.whatsapp.net