0

我正在尝试使用以下代码在我的设备中获取联系人可写帐户列表

        public static final String SYNC_META_DATA = "android.content.SyncAdapter";

    public static final String[] METADATA_CONTACTS_NAMES = new String[] {
            "android.provider.ALTERNATE_CONTACTS_STRUCTURE",
            "android.provider.CONTACTS_STRUCTURE"
    };

final Intent intent = new Intent(SYNC_META_DATA).setPackage(resPackageName);
        final List<ResolveInfo> intentServices =
                        pm.queryIntentServices(intent, PackageManager.GET_META_DATA);
        if (intentServices != null) {
            for (final ResolveInfo resolveInfo : intentServices) {
                final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
                if (serviceInfo == null) {
                    continue;
                }
                for (String metadataName : METADATA_CONTACTS_NAMES) {
                    final XmlResourceParser parser = serviceInfo.loadXmlMetaData(
                            pm, metadataName);
                    if (parser != null) {
                        return parser;
                    }
                }
            }
        }

但我总是将 XmlResourceParser 解析器设为空。所以请帮助我如何获取android中的联系人可写帐户列表

4

1 回答 1

0

有一个 API,您需要遍历所有 SyncAdapter 并检查它们是否supportUploading具有ContactsContract.AUTHORITY权限:

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, "SyncAdapter supports contacts: " + sync.accountType + " - supportsUploading=" + sync.supportsUploading());
    }
}

supportsUploading意味着这是双向同步,即用户可以在她的设备上修改联系人并将更改同步到他们的云帐户。

于 2018-12-20T07:18:05.173 回答