【问题标题】:how can i get Viber contacts (Name and number)?我怎样才能获得 Viber 联系人(姓名和号码)?
【发布时间】:2020-12-23 00:46:34
【问题描述】:

我正在尝试获取 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());

【问题讨论】:

    标签: java android android-studio arraylist android-contacts


    【解决方案1】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多