我有一个使用ActiveAndroid的应用程序,它一直工作正常。然而;现在,当我尝试将模型保存到数据库时,我得到了一个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?
对不起,但我还没有一个孤立的例子。我会努力把东西放在一起。
提前致谢
我知道那里已经有了很好的答案,但我不明白如何最好的方法来修复这个bug并阅读this post Fixing SecurityException requiring a valid ContentProvider on Android 8,它非常有助于修复我的bug我希望它对其他人有用,干杯!
如果你的包与applicationId不同,那么你应该使用applicationId
<provider
android:name="com.activeandroid.content.ContentProvider"
android:authorities="${applicationId}"
android:exported="false" />
我在Android O上遇到了与活动android完全相同的问题。原来我的自定义ContentProvider中的一个方法返回了一个Uri
,有时会返回null,这导致了问题。所以我将@Nullable
注释添加到如下所示的方法中,这解决了问题。
@Nullable
@Override
public Uri insert(Uri uri, ContentValues contentValues) {..}
编辑清单并在侧应用程序节点中添加此提供程序标记节点。
<application ....>
<provider android:name="com.activeandroid.content.ContentProvider"
android:exported="false"
android:enabled="true"
android:authorities="here will be package name of your app"/>
.....
</application>
我用它并修复了我的错误。 Click here for demo。