SecurityException:找不到用户0的提供程序null;在Android 8.0上的ActiveAndroid上 [英] SecurityException: Failed to find provider null for user 0; on ActiveAndroid on Android 8.0

查看:426
本文介绍了SecurityException:找不到用户0的提供程序null;在Android 8.0上的ActiveAndroid上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ActiveAndroid的应用程序,并且运行良好。然而;现在,当我尝试将模型保存到数据库时,出现了SecurityException。

I have an app that is using ActiveAndroid and it's been working fine. However; now when I try to save a model to the database I'm getting a SecurityException.

堆栈为:

Error saving model java.lang.SecurityException: Failed to find provider null for user 0; expected to find a valid ContentProvider for this authority 
at android.os.Parcel.readException(Parcel.java:1942) 
at android.os.Parcel.readException(Parcel.java:1888) 
at android.content.IContentService$Stub$Proxy.notifyChange(IContentService.java:801) 
at android.content.ContentResolver.notifyChange(ContentResolver.java:2046) 
at android.content.ContentResolver.notifyChange(ContentResolver.java:1997) 
at android.content.ContentResolver.notifyChange(ContentResolver.java:1967) 
at com.activeandroid.Model.save(Model.java:162)
[.... local stack removed]

还有其他人遇到过吗?我们是否需要在 AndroidManifest.xml 中指定 Content Provider

Has anyone else experienced this? Do we need to specify the Content Provider in the AndroidManifest.xml?

对不起,但是我还没有一个孤立的例子。我会努力将它们放在一起。

Sorry but I do not have an isolated example of this yet. I will work to put something together.

预先感谢

推荐答案

正如@GeigerGeek所指​​出的那样,Android 26及更高版本上的安全性更改要求您在清单中指定内容提供者。

As pointed out by @GeigerGeek security changes on Android 26 and above require you to specify the content provider in your manifest.

对于ActiveAndroid,您可以将以下内容添加到清单中并更改软件包名称。

For ActiveAndroid you can add the below to your Manifest and change your package name.

<provider
  android:name="com.activeandroid.content.ContentProvider"
  android:authorities="<your.package.name>"
  android:enabled="true"
  android:exported="false">
</provider>

如果在构建过程中使用风味,则可以改用以下方式:

If using flavours on your build process you can use below instead:

android:authorities="${applicationId}"

使用 $ {applicationId} 将有助于基于风味的项目结构,其中每种风味的应用程序包可能会有所不同。

Using ${applicationId} will help in flavor based project structure where application package may be different for each flavors.

有关更多解决方案或信息,请从此处中获取。

For more solutions or info this was taken from here.

这篇关于SecurityException:找不到用户0的提供程序null;在Android 8.0上的ActiveAndroid上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆