FileProvider crash - npe attempting to invoke XmlResourceParser on a null String
You can do this without hardcoding the package name with an additional benefit of being able to run multiple variants on the same device (think release
and debug
with applicationIdSuffix
, see these issues):
Based on FileProvider.java:560
final ProviderInfo info = context.getPackageManager()
.resolveContentProvider(authority, PackageManager.GET_META_DATA);
final XmlResourceParser in = info.loadXmlMetaData( //560
context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
you were using the wrong authority
and it didn't find the ContentProvider
(info == null
).
Change your manifest to (${applicationId}
will be replaced by Manifest Merger)
android:authorities="${applicationId}.share"
and
Uri uri = FileProvider.getUriForFile(context, context.getPackageName() + ".share", result);
The .share
suffix is optional, in case you have a real ContentProvider
which is better to have the package name as the authority.
The problem was that in Manifest I had this line:
android:authorities="com.example.asd.fileprovider"
and when calling getUriForFile I was passing:
Uri contentUri = FileProvider.getUriForFile(getApplicationContext(), "com.example.asd", newFile);
So changed from "com.example.asd"
to "com.example.asd.fileprovider"
and it worked