简体   繁体   中英

Authority com.android.contacts not found exception when doing applyBatch

I have this code:

context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);

On some phones (user report it to me) it causes a:

java.lang.IllegalArgumentException: Unknown authority com.android.contacts

However similar authority is listed within installed packages:

contacts;com.android.contacts

or

com.google.contacts.gal.provider

Note contacts; prefix - does not seem good to me. I used this code to get it:

String message="";
for (android.content.pm.PackageInfo pack : context.getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS)) {
 ProviderInfo[] providers = pack.providers;
 if (providers != null) {
  for (ProviderInfo provider : providers) {
  message=message+", "+provider.authority;
 }
 }
}

Do you think it's appropriate to failover to contacts;com.android.contact if com.android.contacts fails??

Contacts provider lists "contacts;com.android.contacts" in his authorities. This list should be parsed by a content resolver, you don't need to use this string as a authority.

Probably you need to find out more about phones with this problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM