In the vast en-SO found the answer , the comments say that the example is working. I try to do the same in my application, but on the first attempt it seems as if WhatsApp launched and immediately closes. In subsequent attempts, nothing happens at all, the only reaction is a string in the logs:
V / WhatsApp: Total WhatsApp Contacts: 17
I do it like this:
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); Uri uri = ContactUriHelper.getUriFromPhoneNumber(contact.getPhone().getNumber(), getApplicationContext()); intent.setDataAndType(Uri.parse("content://com.android.contacts/data/2021"), //Uri.parse("content://com.android.contacts/data/_id") "vnd.android.cursor.item/vnd.com.whatsapp.voip.call"); intent.setPackage("com.whatsapp"); startActivity(intent); Uri tried to transmit it in a string and by the uri object itself - nothing changed.
Uri I get as follows
public static Uri getUriFromPhoneNumber(String phoneNumber, Context context) { Uri uri = null; String contactId = getContactIdByPhoneNumber(phoneNumber, context); if (!TextUtils.isEmpty(contactId)) { Cursor cursor = context.getContentResolver().query( ContactsContract.Data.CONTENT_URI, new String[]{ContactsContract.Data._ID}, ContactsContract.Data.DATA2 + "=? AND " + ContactsContract.Data.CONTACT_ID + " = ?", new String[]{"Viber", contactId}, null); if (cursor != null) { Log.wtf(TAG, cursor.toString()); while (cursor.moveToNext()) { String id = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Data._ID)); if (!TextUtils.isEmpty(id)) { uri = Uri.parse(ContactsContract.Data.CONTENT_URI + "/" + id); Log.d(TAG, "URI: " + uri.toString()); break; } } cursor.close(); } } return uri; } private static String getContactIdByPhoneNumber(String phoneNumber, Context context) { ContentResolver contentResolver = context.getContentResolver(); String contactId = null; Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); String[] projection = new String[]{ContactsContract.PhoneLookup._ID}; Cursor cursor = contentResolver.query( uri, projection, null, null, null); if (cursor != null) { while (cursor.moveToNext()) { contactId = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID)); } cursor.close(); } Log.wtf(TAG, "ContactID: " + contactId); return contactId; } What could be the problem?