I rerally didn't want to ask this question, but I couldn't find any solutions.
In my manifest I have declared FileProvider:
<provider android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths"/>
</provider>
It requires #xml/provider_paths to work. In my resources folder I have created provider_paths.xml file and copy-pasted this code:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="files" path="."/>
</paths>
However Android Studio IDE throws me that kind of error:
Element paths must be declared
My screenshot:
Move the provider_path.xml from values directory to
res/xml/provider_paths.xml
To specify the directories, start by creating the file filepaths.xml in the res/xml/ subdirectory of your project. In this file, specify the directories by adding an XML element for each directory.
Refer Specify Sharable Directories
Related
This is my manifest file
<application>
<provider
android:authorities="${applicationId}.fileprovider"
android:name="android.support.v4.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
</application>
This is my file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<root-path name="root" path="" />
<external-path name="external_storage_root" path="." />
<external-path name="external_storage_download" path="Download" />
</paths>
When I try and execute my app I get the following errors
Error failed processing manifest. Error resource xml/file_paths
(aka com.companyname.ProjectName:xml/file_paths) not found.
This error is likely caused by an issue with the AndroidManifest.xml
file or an Android manifest generation attribute in a source code
file. Project Name
C:..\source\repos\ProjectName\Properties\AndroidManifest.xml
I searched google and tried alot of solutions but non of them actually worked soo here i am now, hopefully someone can help me.
Did you create a folder named xml in your Resources folder ?
like below:
I upgraded an existing Xamarin Forms 4.8x to XF 5.0x and it is throwing an exception on loading the app in the emulator:
Java.Lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path:
I truncated after emulator: as the rest seemed quite specific to my app.
I am stuck - any help is appreciated!
If you receive the following error, it is because you are using AndroidX. To resolve this error, follow the instructions).
Remove the previous <provider android:name="android.support.v4.content.FileProvider"> tag
(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>
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.
Add the following code:
<?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>
I need to create a directory to store user video files in Internal Storage.
In some part of the code I have this:
var path = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
System.IO.Directory.CreateDirectory(path);
When I debug, path variable is actually: "/data/data/com.companyname.MyApp/files/Videos"
When I browse device files, the closest target folder is this: "This PC\MyDevice\Internal storage\Android\data"
When I browse that folder, no new folder was created. I was expecting to have com.companyname.MyApp/files/Videos folder structure, but it was not created, even when no exception was thrown.
How can I do it?
Thanks
Jaime
You need to add File provider in the manifest
Define file_paths.xml
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="my_images" path="images/"/>
<files-path name="my_docs" path="docs/"/>
</paths>
and add it into manifest
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mydomain.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
Finally, I had a misconception about Internal and External storage.
What I was seeing in Windows Explorer is in fact, external storage, so I used:
Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryMovies)
That points to the "Movies" directory where I could save the MP4 file in order to view in the Android device.
Regards
Jaime
I am trying to add the xml folder and an xml file named file_path.xml to implement the Fileprovider (android). However, when I add the following (Resources/xml/file_path.xml) content the application does not start anymore.
<paths>
<files-path name="files" path="."/>
</paths>
I get a null pointer exception as it cant read these resource. It doesnt matter whether I add the provider tag in manifest or not. I am very new in Xamarin.
Go to the properties of this file, select Build Action "AndroidResource".
In android manifest, inside the tag application, do this:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths"/>
</provider>
https://developer.android.com/reference/android/support/v4/content/FileProvider
I need to share pdf files from my assets folder.
The pdf file changes based on language.
Assets structure is like -
assets
folder
countryA
languageA
pdfA
languageB
pdfB
countryB
languageA
pdfA
languageC
pdfC
My Android manifest file -
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths"/>
</provider>
When the following code runs
FileProvider.getUriForFile(getActivity(),
BuildConfig.APPLICATION_ID + ".provider",
new File("String file name"));
I am getting a java.lang.IllegalArgumentException: Failed to find configured root that contains /file:/android_asset/folder/countryA/languageA/file.pdf
I believe it is because the path in the provider xml is not configured.
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path name="my_file_name" path="."/>
</paths>
I have used files-path as the files are under assets folder.
Since the files are nested how do i configure the provider path.
I have consulted the following links
Link1
Link2
Link3