如何获取viber联系人(姓名和号码)?

agxfikkp  于 2021-07-05  发布在  Java
关注(0)|答案(1)|浏览(507)

我在找viber的联系人。使用此方法,我可以获得使用viber的联系人的姓名,但也可以获得其他不使用viber的联系人的姓名(选择方法不正常)。我无法获得viber联系人的号码。你知道我该怎么解决这个问题吗?

Cursor cursor2 = getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI
            ,null
            , ContactsContract.RawContacts.ACCOUNT_TYPE_AND_DATA_SET + "= ?"
            ,new String[] { "com.viber.voip" }
            , null);

    while (cursor2.moveToNext())
    {
        String name=cursor2.getString(cursor2.getColumnIndex(ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY));

        //Adding contact name into the ArrayList
        myViberContacts.add(name+"\n");
        //Giving the TextView the value of the arraylist
        emervib.setText(myViberContacts.toString());
bksxznpy

bksxznpy1#

我相信这个代码应该适合你:

String MIMETYPE_VIBER_MESSAGE = "vnd.android.cursor.item/vnd.com.viber.voip.viber_number_message";
String selection = Data.MIMETYPE + "=?";
String[] selectionArgs = new String[] { MIMETYPE_VIBER_MESSAGE };
String[] projection = new String[] { Data.CONTACT_ID, Data.DATA1, Data.DISPLAY_NAME };

Cursor cur = getContentResolver().query(Data.CONTENT_URI, projection, selection, selectionArgs, null);

DatabaseUtils.dumpCursor(cur); // check logcat for the results

相关问题