我试图在我的应用程序中使用所有Telegram联系人,这是我的代码:
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
吗?或者我在哪里可以找到电报的帐户类型?
感谢您的关注。
答案 0 :(得分: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());
希望能帮助任何人。