我正在尝试通过设置联系人在 WhatsApp 上发送消息。显示联系人的 WhatsApp 个人资料,但EditText的内容未设置为 WhatsApp 个人资料。
我的代码是:
String id =etxnumber.getText().toString();
Uri uri = Uri.parse("smsto:" + id);
String text1 =etxmsg.getText().toString();
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setPackage("com.whatsapp");
i.putExtra(Intent.EXTRA_TEXT, text1);
i.setType("text/plain");
startActivity(i);
错误是:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO typ=text/plain pkg=com.whatsapp (has extras) }
答案 0 :(得分:0)
试试这个:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
答案 1 :(得分:0)
尝试以下代码
String id =etxnumber.getText().toString();
String text1 =etxmsg.getText().toString();
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse(
"content://com.android.contacts/data/" +
id));
i.setPackage("com.whatsapp");
i.putExtra(Intent.EXTRA_TEXT, text1);
i.setType("text/plain");
startActivity(i);