问题
I am using file provider to save photo to a given destination. I get:
java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS meta-data while trying to open activity to capture image from camera.
My manifest.xml file:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/paths" />
</provider>
My paths.xml file:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="content" path="Android/data/com.my_package_name/files/" />
</paths>
and Java code:
File externalFilesDirectory = this.getExternalFilesDir(null);
File imageFile = File.createTempFile(
imageFileName,
".jpg",
externalFilesDirectory
);
Uri photoURI = FileProvider.getUriForFile(this, "com.example", imageFile);
Last line gives the exception. What am I missing here? I've followed tutorial from official Android development site (https://developer.android.com/training/camera/photobasics.html)
回答1:
I found the solution. The problem was that my authority name didn't end with ".fileprovider". Fixed.
回答2:
Even when you have authorities properly set up to the appId and there is the FileProvider setup , you should ideally delete the caches , i.e. Delete .gradle and .idea folders or probably Invalidate the caches and restart which enables you to redownload the gradle dependencies again and then it worked for me :) Hope this might help someone
来源:https://stackoverflow.com/questions/38978198/android-file-provider-illegal-argument-exception