我正在尝试使用以下代码获取设备中的联系人可写帐户列表
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解析器设为null。所以请帮我如何获取android中可联系联系人的帐户列表
答案 0 :(得分:0)
有一个API,您需要遍历所有SyncAdapter并检查它们是否var topSafeAreaHeight: CGFloat = 0
var bottomSafeAreaHeight: CGFloat = 0
if #available(iOS 11.0, *) {
let window = UIApplication.shared.windows[0]
let safeFrame = window.safeAreaLayoutGuide.layoutFrame
topSafeAreaHeight = safeFrame.minY
bottomSafeAreaHeight = window.frame.maxY - safeFrame.maxY
}
并具有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());
}
}
表示这是双向同步,即用户可以在其设备上修改联系人并将更改同步到他们的云帐户。