1

I use Xamarin to create Android Apps. I want to open my app's file in other app (let say .docx file in microsoft word app, and etc). I use FileProvider, but always get this error:

Exception:Java.Lang.IllegalArgumentException: Failed to find configured root that contains...

This is my FileProvider file:

[Android.App.MetaData("android.support.FILE_PROVIDER_PATHS", Resource = "@xml/file_provider_path")]
[Android.Content.ContentProvider(new System.String[] { "${applicationId}.fileProvider" }, Exported = false, GrantUriPermissions = true, Name = "Android.Support.V4.Content.FileProvider")]
public  class AppFileProvider : Android.Support.V4.Content.FileProvider
{
    public AppFileProvider()
    {

    }

}

I also have .xml file with name file_provider_path.xml with content:

<?xml version="1.0" encoding="UTF-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
  <files-path name="file_provider_path" path="/" />
</paths>

and to get file uri I use:

Java.IO.File _file = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory, "document1.docx");
AppFileProvider.GetUriForFile(this.ApplicationContext, this.Application.ApplicationContext.PackageName + ".fileProvider", _file)

Can you help me to find solution?

mas_bejo
  • 597
  • 2
  • 6
  • 22
  • 2
    A `` element points to your app's internal storage, but that file is in external storage. You want `` instead. Also, note that direct file system access has been severely restricted, starting with Android Q, so you'll likely have to change how you're handling that. – Mike M. Nov 11 '19 at 04:44
  • Thanks @MikeM. that solve my problem.. – mas_bejo Nov 13 '19 at 03:04

1 Answers1

0

Based on Mike's Comment, I read this https://developer.android.com/reference/android/support/v4/content/FileProvider#SpecifyFiles . And I need to set "../" as my path in file_provider_path.xml, because I did not save the file on files folder.

mas_bejo
  • 597
  • 2
  • 6
  • 22