6

我想从我的应用程序中打开什么是应用程序对话活动cmp=com.whatsapp/.Conversation

我怎样才能做到这一点?我有联系电话号码、联系人 ID、联系人原始 ID,并且还有特定联系人的应用程序 uri。

private void openWhatsApp(String id) {

    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/data/"+id));
    Log.v("ssssss", s);
    i.setType("vnd.android.cursor.item/vnd.com.whatsapp.profile");
    i.setComponent(new ComponentName("com.whatsapp", ".Conversation"));
    startActivity(i);
}


04-20 18:13:45.794: I/ActivityManager(1862): START
{act=android.intent.action.VIEW
dat=content://com.android.contacts/data/8269
typ=vnd.android.cursor.item/vnd.com.whatsapp.profile
cmp=com.whatsapp/.accountsync.ProfileActivity} from pid 32159


04-20 18:42:11.317: I/ActivityManager(1862): START {flg=0x14000000 cmp=com.whatsapp/.Conversation (has extras)} from pid 1150
4

5 回答 5

6
private void openWhatsApp(String id) {

Cursor c = 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 是什么应用程序的 uri0987654321@s.whatsapp.net

于 2013-04-30T11:37:04.810 回答
1

试试这个代码:

String smsNumber="919426640584@s.whatsapp.net";
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra("sms_body", "Prakash Gajera");
i.setPackage("com.whatsapp");
startActivity(i);
于 2016-07-06T12:35:04.960 回答
1

当用户不知道联系电话时,我的最终解决方案。

您也可以选择设置预格式化文本。

    try {
        String whatsAppRoot = "http://api.whatsapp.com/";
        String number = "send?phone=+xxxxxxxxxxx"; //here the mobile number with its international prefix
        String text = "&text=HERE YOUR TEXT";
        String uri = whatsAppRoot+number+text;

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(uri));
        startActivity(intent);
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), 
        "WhatsApp cannot be opened", Toast.LENGTH_SHORT).show();
    }
于 2018-09-02T09:35:27.497 回答
0

你可以使用这个例子

startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse(
                                    "https://api.whatsapp.com/send?phone=+628119xxx&text=I'm%20interested%20in%20your%20car%20for%20sale"
                            )));
于 2017-09-30T04:59:32.940 回答
0
 String KEY_QUICK_REPLY_TEXT = "Dear Valued Customer Thank you for contacting us your reference Number is "+refernceNumber ;
   Intent intent = new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("http://api.whatsapp.com/send?phone="+phone +"&text="+KEY_QUICK_REPLY_TEXT));
                            startActivity(intent);

Toast.makeText(MainActivity.this, response, Toast.LENGTH_SHORT).show();
于 2018-10-05T06:31:10.947 回答