java.lang.SecurityException: Failed to find provider null for user 0; expected to find a valid ContentProvider for this authority

产生上述异常的原因可能为:在Android 8.0 设备以上的时候, 没有提供相对应authority key的ContentProvider。

原因如下:

Android 8.0 行为变更:https://developer.android.com/about/versions/oreo/android-8.0-changes#ccn

Android java.lang.SecurityException: Failed to find provider异常说明解决方法:

  1. 新建个XXContentProvider继承ContentProvider(如果有需要的话建议把ContentProvider中的abstract方法重新实现下,提升安全性)。
  2. 在AndroidManifest.xml 声明provider,并且在provider中添加授权key。
  3. 在使用notifyChange方法的时候,给相应的Uri添加authority key(Uri.Builder.authority(xxx),此处的authority key要与AndroidManifest文件中的key一致。)

示例:

自定义ContentProvider

Android java.lang.SecurityException: Failed to find provider异常说明

AndroidManifest.xml

Android java.lang.SecurityException: Failed to find provider异常说明

使用了activeAndroid的朋友可以直接使用com.activeandroid.content.ContentProvider这个实现类。

相关文章:

  • 2022-12-23
  • 2021-10-05
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2021-11-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2022-12-23
相关资源
相似解决方案