【问题标题】:Getting Contact ACCOUNT_NAME and ACCOUNT_TYPE as Null in motorolla device在 motorolla 设备中获取联系人 ACCOUNT_NAME 和 ACCOUNT_TYPE 作为 Null
【发布时间】:2012-10-06 11:40:56
【问题描述】:

我正在尝试获取设备中所有联系人的帐户名称和帐户类型,但对于 motorolla 设备(motorolla argon mini),我得到 ACCOUNT_TYPE 和 ACCOUNT_NAME 为空。

使用的代码 -

uri = ContactsContract.Data.CONTENT_URI;

projection = new String[]   {RawContacts.CONTACT_ID,RawContacts.ACCOUNT_NAME,RawContacts.ACCOUNT_TYPE,   StructuredName.GIVEN_NAME,StructuredName.FAMILY_NAME,StructuredName.MIDDLE_NAME , ContactsContract.Data.MIMETYPE};

if(uri!=null)
            {
                mQueryHandler.startQuery(mDbIds[i],
                        null,
                        uri,
                        projection,
                        selection,
                        null,
                        null);
            }

【问题讨论】:

    标签: android android-contacts android-contentresolver


    【解决方案1】:

    在原始联系人表中,“ACCOUNT_TYPE”和“ACCOUNT_NAME”在电话联系人的情况下可以为空,在 google 联系人或 facebook 等情况下不能为空。

    【讨论】:

    • 感谢您的回复。我的问题是我得到的“ACCOUNT_TYPE”和“ACCOUNT_NAME”只有 motorolla argon mini 为空,对于其他设备我得到了正确的值。
    • 这取决于原始设备制造商。您不能在默认 account_type 为 com.google 的设备(如 Google 像素)中使用空帐户类型。
    【解决方案2】:

    在原生联系人应用中,您可以拥有来自不同来源的联系人。这些联系人可以是您手机、SIM、Google 联系人等中的联系人。
    account_typeaccount_name 的值完全取决于设备制造商(如三星、摩托罗拉、Google Pixel 等)。 例如,在您的情况下,摩托罗拉手机联系人的 account_typeaccount_name 为 null,而其他 OEM 可能不是这样。

    如果您想知道联系人的来源(电话/SIM 联系人除外) 您可以使用以下代码遍历所有帐户并获取不同的联系人来源。

    final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes();
    for (SyncAdapterType sync : syncs) {
        Log.d(TAG, "found SyncAdapter: " + sync.accountType);
        if (ContactsContract.AUTHORITY.equals(sync.authority)) {
            Log.d(TAG, "found SyncAdapter that supports contacts: " + sync.accountType);
            // we'll now get a list of all accounts under that accountType:
            Account[] accounts = AccountManager.get(this).getAccountsByType(sync.accountType);
            for (Account account : accounts) {
               Log.d(TAG, account.type + " |  " + account.name);
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-10-28
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2017-02-03
      • 2023-04-06
      • 1970-01-01
      • 2017-05-06
      相关资源
      最近更新 更多