Hello,
Welcome to our Microsoft Q&A platform!
But error, vs2022 tell that
System.ArgumentException: 'Unable to get file location. This most likely means that the file provider information is not set in your Android Manifest file. Please check >documentation on how to set this up in your project.'I have add the info to AndroidManifest.xml, but error too.
No, you did not add <provider>
tag like following format to the AndroidManifest.xml.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.startactivitydemo11">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" />
<application android:label="StartActivityDemo11.Android" android:theme="@style/MainTheme">
<!--add this part-->
<provider android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
</manifest>
Here are steps to add the <provider>
tag.
If you target framework set Android 10 or later.
1 (AndroidX) Add the following to your AndroidManifest.xml inside the <application> tags:
<provider android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
2 Add a new folder called xml into your Resources folder and add a new XML file called file_paths.xml
. Make sure that this XML file has a Build Action of: AndroidResource
.
3 Add the following code to file_paths.xml
:
<?xml version="1.0" encoding="utf-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="my_images" path="Pictures" />
<external-files-path name="my_movies" path="Movies" />
</paths>
If you target framework blew Android 10 .
(Non AndroidX) Add the following to your AndroidManifest.xml inside the <application> tags: Other steps is the same as above AndroidX
<provider android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
You can read more at: https://developer.android.com/training/camera/photobasics.html
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.