SecurityException:无法为用户0找到提供程序null;在Android 8.0上的ActiveAndroid上

问题描述 投票:22回答:10

我有一个使用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?

对不起,但我还没有一个孤立的例子。我会努力把东西放在一起。

提前致谢

android securityexception activeandroid android-8.0-oreo
10个回答
-1
投票

我知道那里已经有了很好的答案,但我不明白如何最好的方法来修复这个bug并阅读this post Fixing SecurityException requiring a valid ContentProvider on Android 8,它非常有助于修复我的bug我希望它对其他人有用,干杯!


0
投票

如果你的包与applicationId不同,那么你应该使用applicationId

<provider
            android:name="com.activeandroid.content.ContentProvider"
            android:authorities="${applicationId}"
            android:exported="false" />

-1
投票

我在Android O上遇到了与活动android完全相同的问题。原来我的自定义ContentProvider中的一个方法返回了一个Uri,有时会返回null,这导致了问题。所以我将@Nullable注释添加到如下所示的方法中,这解决了问题。

@Nullable
@Override
public Uri insert(Uri uri, ContentValues contentValues) {..}

-1
投票

编辑清单并在侧应用程序节点中添加此提供程序标记节点。

<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

© www.soinside.com 2019 - 2024. All rights reserved.