通过WhatsApp从4.4.4中不起作用的android应用程序向特定联系人发送消息
我正在开发一个android应用程序,我需要从WhatsApp向特定联系人发送消息。代码在android版本4.4中不起作用。我尝试了以下代码:通过WhatsApp从4.4.4中不起作用的android应用程序向特定联系人发送消息,android,Android,我正在开发一个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"); sta
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, ""));
}
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();
}
请尝试以下代码:
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, ""));
}
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是什么样的应用程序uri
0987654321@s.whatsapp.net感谢您的回复,但对于未知号码,它不起作用。我需要给未知的人发个信息contact@sarikakashidWhatsapp正在打开聊天记录,但不会根据您的代码接收文本并发送