0

我试图让所有的电报联系,在我的应用程序中使用的所有电报接触,这里是我的代码:得到保存在手机

 Cursor c = getContentResolver().query(
      ContactsContract.RawContacts.CONTENT_URI, 
      new String[] { ContactsContract.RawContacts.CONTACT_ID, ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY }, 
      ContactsContract.RawContacts.ACCOUNT_TYPE + "= ?", 
      new String[] { "org.telegram.messenger.account" }, 
      null); 

    ArrayList<String> myTelegramappContacts = new ArrayList<String>(); 
    int contactNameColumn = c.getColumnIndex(ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY); 
    while (c.moveToNext()) 
    { 
     // You can also read RawContacts.CONTACT_ID to read the 
     // ContactsContract.Contacts table or any of the other related ones. 
     myTelegramappContacts.add(c.getString(contactNameColumn)); 
    } 

,但它不返回我任何接触!

我的问题是什么?

org.telegram.messenger.account是否适用于帐户类型?或者我可以在哪里找到电报的帐户类型?

感谢您的关注。

回答

1

终于找到了,在报文的真正ACCOUNT_TYPE是

org.telegram.messenger 

,也可以通过这个代码中找到在手机中的所有帐户类型:

final Map<String, String> result = new HashMap<>(); 
    final Cursor cursor = getContentResolver() 
      .query(ContactsContract.RawContacts.CONTENT_URI, new String[]{ContactsContract.RawContacts.ACCOUNT_TYPE, ContactsContract.RawContacts.ACCOUNT_NAME}, 
        null, null, 
        null); 
    final int accountNameIdx = cursor.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_NAME); 
    final int accountTypeIdx = cursor.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE); 
    for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { 
     result.put(cursor.getString(accountTypeIdx), cursor.getString(accountNameIdx)); 
    } 
    cursor.close(); 
    Log.d("AppLog", "accounts found:"); 
    for (Map.Entry<String, String> account : result.entrySet()) 
     Log.d("AppLog", account.getKey() + ":" + account.getValue()); 

,希望能帮助任何人埃尔斯。

相关问题