Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

android - How can I open WhatsApp's conversation activity using contact data?

I want open what's app conversation activity cmp=com.whatsapp/.Conversation from my app.

How can I do this? I have contact phone number, contact id, contact raw id and also have what's app uri for a particular contact.

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
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();
}

Where id is what's app uri like 0987654321@s.whatsapp.net


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...