SecurityException: Failed to find provider null for user 0; on ActiveAndroid on Android 8.0

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.

The stack is:

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]

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.

Thanks in advance

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

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}"

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.

Fixing SecurityException requiring a valid ContentProvider on , SecurityException: Failed to find provider for user 0; expected to find a valid ContentProvider for this authority. Android documentation says: Android 8.0 (API​  I'm getting the following on Android 8 devices when running a content provider operation from another PID: Caused by: java.lang.SecurityException: Failed to find provider null for user 0; expected to find a valid ContentProvider for this authority

For hot fix, set your

compileSdkVersion 25
targetSDKVersion 25

and you will ignore android O features. It will save your day!

important for hot fix:

But this solution will be invalid.

August 2018: New apps required to target API level 26 (Android 8.0) or higher. November 2018: Updates to existing apps required to target API level 26 or higher. 2019 onwards: Each year the targetSdkVersion requirement will advance. Within one year following each Android dessert release, new apps and app updates will need to target the corresponding API level or higher.

Another ways, you can fix with ActiveAndroid but It is deprecated now. You can try or you can try ReActiveAndroid

with ActiveAndroid, visit https://github.com/pardom/ActiveAndroid/issues/536#issuecomment-344470558

When project have defined model classes in java source code through addModelClasses configuration method application will still be crashing cause model classes wont be loaded through that configuration. In that situation You need to move model definition to the AndroidManifest.xml file.

AndroidManifest.xml

<provider
    android:name=".content.DatabaseContentProvider"
    android:authorities="your package name"
    android:exported="false" />

DatabaseContentProvider.java

...
import com.activeandroid.content.ContentProvider;
...

public class DatabaseContentProvider extends ContentProvider {

@Override
protected Configuration getConfiguration() {
    Configuration.Builder builder = new Configuration.Builder(getContext());
    builder.addModelClass(SomeModel.class);
    builder.addModelClass(OtherModel.class);
    return builder.create();
 }}

If you are doing something with FileProvider, don't miss to change package name

 Uri contentUri = FileProvider.getUriForFile(mContext,
            "your package name", new File(mImageFilePath));

.save failing on Android O device · Issue #536 · pardom-zz , I recently just updated my device to Android O and now the .save methods no longer work. java.lang.SecurityException: Failed to find provider null for user 0; expected to find a valid notifyChange(ContentResolver.java:1967) at com.​activeandroid. Crash when save data in android 8.0 #535. Closed. java.lang.SecurityException: Failed to find provider null for user 0; expected to find a valid ContentProvider for this authority #553. ieewbbwe opened this issue May 23, 2018 · 1 comment. java.lang.SecurityException: Failed to find provider null for user 0; expected to find a valid ContentProvider for this authority.

Android O apparently requires the use of a custom ContentProvider for database usage, even if you do not intend to share your data with other applications.

https://developer.android.com/about/versions/oreo/android-8.0-changes.html

Your custom class must be defined in a provider tag within your application tag in AndroidManifest.xml. If applicable, set exported=false to protect your data from external usage.

<provider android:name=".MyContentProvider"
    android:exported="false"
    android:authorities="com.your_app_path.MyContentProvider"/>

For me the problem arose because I was calling notifyChange from the contentResolver. I ended up not needing this, so I was able to avoid implementation a ContentProvider.

java.lang.SecurityException: Failed to find provider null for user 0 , java.lang.SecurityExceptionFailed to find provider null for user 0; expected to find a valid ContentResolver.notifyChange() has thrown a SecurityException. Android. 0. 3. 1 https://github.com/pardom-zz/ActiveAndroid/issues/553 SecurityException: Failed to find provider null for user 0; on ActiveAndroid on Android 8.0. My app use ActiveAndroid and I have problems only Android Oreo when make any action with my models. java.lang.SecurityException: Failed to find provider null for user 0; expected to find a valid

if your package is different from your applicationId then you should use the applicationId

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

java.lang.SecurityException: Failed to find provider KickObject for , SecurityExceptionFailed to find provider KickObject for user 0; expected to find a valid Failed to find provider null for user 0; on ActiveAndroid on Android 8.0. java.lang.SecurityException: Failed to find provider for user 0; expected to find a valid ContentProvider for this authority Android documentation says: Android 8.0 (API level 26) changes how ContentResolver.notifyChange() and registerContentObserver(Uri, boolean,

Maybe because of your uri is null when you use notifyChange, https://developer.android.com/about/versions/oreo/android-8.0-changes.html#ccn

Android O will add check for provider:

311 .checkContentProviderAccess(uri.getAuthority(), userHandle);
312 if (msg != null) {
313 if (targetSdkVersion >= Build.VERSION_CODES.O) {
314 throw new **SecurityException**(msg);
315 } else {

Android java.lang.SecurityException: Failed to find provider , SecurityException: Failed to find provider null for user 0; expected to find a valid The reason for the above exception may be: When the Android 8.0 device is Friends who use activeAndroid can directly use the com.activeandroid.content. java.lang.SecurityException: Failed to find provider questions f user 0; expected to find a valid ContentProvider for this authority 10-31 android share | improve this question

Android Question, SecurityException: Failed to find provider org.abtollc.db for user 0; expected to provider-null-for-user-0-on-activeandroid-on) - but I really can't see how can I fix it​ could you help? Doesn't work in Android 8 AND target 26. Android 8.0 (API level 26) changes how ContentResolver.notifyChange() and registerContentObserver(Uri, boolean, ContentObserver) behave for apps targeting Android 8.0. These APIs now require that a valid ContentProvider is defined for the authority in all Uris.

SecurityException: Failed to find provider null for user 0; expected to find a valid notifyChange(ContentResolver.java:1967) at com.activeandroid. Fixing SecurityException requiring a valid ContentProvider on Android 8,  Failed to find provider com.google.android.gsf.gservices for user 0; expected to find a valid ContentProvider for this authority #534 Closed LiuDongCai opened this issue Jun 14, 2018 · 6 comments

"java.lang.SecurityException: Failed to find provider for user 0; expected to find a valid ContentProvider for this authority" Everything works just fine when targeting api 25. I'm testing on Android 8.0, Pixel and using version 2.1.4 of PickImage.

Comments
  • "Failed to find provider null" suggests a malformed Uri, one whose authority string is either missing or literally "null".
  • I get the same crash, but with something else than "null" as provider in the stacktrace. Dont know why this is happening, but its only occurring on Android 8...
  • This one is driving me crazy. Targeting SDK 25 works fine, targeting 26+ crashes with exactly this error. I HAVE set the authority in the Provider correctly. Still this crash. I have NO IDEA what this is about. Of course my Uri is not null at the call! Do you now anything new??
  • @Velval's answer below is probably the correct one: stackoverflow.com/a/47664761/211292
  • note: authorities may be other strings, not just your package name
  • I don't think ReActiveAndroid is from the same team. "Unfortunately, the author of [ActiveAndroid] stopped maintaining it, so I decided to continue maintain the library instead of him."
  • This doesn't fix the problem.