The phone book presents the following features of social networks, how to add the same features to your application?

Through the supplier of contacts I get to the right lines.

Uri rawContactUri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, rawContactId); Uri entityUri = Uri.withAppendedPath(rawContactUri, ContactsContract.RawContacts.Entity.CONTENT_DIRECTORY); Cursor c = getActivity().getContentResolver().query(entityUri, new String[]{ContactsContract.RawContacts.SOURCE_ID, ContactsContract.RawContacts.Entity.DATA_ID, ContactsContract.RawContacts.Entity.MIMETYPE, ContactsContract.RawContacts.Entity.DATA1, ContactsContract.RawContacts.Entity.DATA2, ContactsContract.RawContacts.Entity.DATA3}, null, null, null); try { while (c.moveToNext()) { String sourceId = c.getString(0); if (!c.isNull(1)) { String mimeType = c.getString(2); String data = c.getString(3); Log.d(TAG, "sourceId = " + sourceId); Log.d(TAG, "mimeType = " + mimeType); Log.d(TAG, "data = " + data); Log.d(TAG, "data = " + c.getString(4)); Log.d(TAG, "data = " + c.getString(5)); } } } finally { c.close(); } 

Here is the log enter image description here

And how to continue to run the desired Intent ? Trying this way

 Uri singleUri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, rawContactId); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(singleUri, "vnd.android.cursor.item/vnd.com.vkontakte.android.profile"); startActivity(intent); 

But nothing comes out, what am I doing wrong?

The solution is found, maybe someone will benefit

 String contactId = "111"; // - id пользователя в таблице ContactsContract.Contacts long rawContactId = 0; // - id пользователя в таблице ContactsContract.RawContacts 

We request contact data from various accounts

 Cursor curIcon = getActivity().getContentResolver(). query(ContactsContract.RawContacts.CONTENT_URI, null, ContactsContract.RawContacts.CONTACT_ID + " = ?", new String[]{contactId }, null); curIcon.moveToFirst(); do { rawContactId = curIcon.getLong(curIcon.getColumnIndex(ContactsContract.RawContacts._ID)); Log.d(TAG, "rawContactId = " + rawContactId); Log.d(TAG, "ACCOUNT_TYPE = " + curIcon.getString(curIcon.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE))); } while (curIcon.moveToNext()); curIcon.close(); 

We are requesting contact data from the ContactsContract.Data table

  Uri rawContactUri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, rawContactId ); Uri entityUri = Uri.withAppendedPath(rawContactUri, ContactsContract.RawContacts.Entity.CONTENT_DIRECTORY); Cursor c = getActivity().getContentResolver().query(entityUri, new String[]{ContactsContract.RawContacts.SOURCE_ID, ContactsContract.RawContacts.Entity.DATA_ID, // _id записи в таблице ContactsContract.Data ContactsContract.RawContacts.Entity.MIMETYPE, // тип данных ContactsContract.RawContacts.Entity.DATA1, // тут будет идентефикатор пользователя ContactsContract.RawContacts.Entity.DATA2, // тут будет название соцсети ContactsContract.RawContacts.Entity.DATA3}, // тут будет описание действия/функции null, null, null); try { while (c.moveToNext()) { if (!c.isNull(1)) { String mimeType = c.getString(2); long data_id = c.getLong(1); Log.d(TAG, "data_id = " + data_id ); Log.d(TAG, "mimeType = " + mimeType); } } } finally { c.close(); } 

Well, run the desired function

 Uri singleUri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, data_id ); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(singleUri, mimeType ); startActivity(intent); 

    1 answer 1

    You must also specify the package that will process your Intent . For example, sending a message via Viber will look like this:

     Intent intent = new Intent(Intent.ACTION_SEND); intent.setPackage("com.viber.voip"); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "Hello World!"); 

    Pay attention to putExtra() - it is for each Intent'a his - I suspect that for VKontakte he is also his - read the docks.

    Update

    To open a VKontakte dialog for a specific contact, you must call:

     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("vkontakte://profile/%d", contactId))); 

    where contactId is the contact identifier

    • I have already tried it. This option does not open the dialogue with the desired contact, it will open the application, where in the future you need to select the recipient. And how to get access directly to the dialogue with a specific user in a particular application? - Andrei Ryabov
    • Then reformulate the question - what do you want then? Intent in your performance anyway, please open another application ... - Barmaley
    • After contacting the supplier of contacts, I get the data of the RawContacts table for a specific contact, entered there by a specific application, these data are visible in the logs. mimeType - as I understand the data type, assigned to the intent by the setType method, the necessary application has a configured intent filter to intercept it, but how to transfer the user ID (it is contained in the ContactsContract.RawContacts.Entity.DATA1 column) - Andrey Ryabov
    • So you want to open the contact book in another application (or rather, the dialogue with the desired contact)? If so then reformulate the question. Otherwise, the question is misleading about your intentions - Barmaley
    • The question is where it is necessary, in my first sentence of the question and the first screenshot exhaustively explain the essence of the question. The functions of social networks appear after synchronization of the social network application, and for their implementation it is necessary to contact the supplier of contacts for the necessary data, just this process was not clear to me. - Andrei Ryabov