Forum Xamarin.Android

how i can use my /storage/ and start another app ?

cerioncerion Member ✭✭

I use FileProvider from examples, but it doesnt work, I can't figure out where I made the mistake
me need open pdf in my storage in another application
my code:
string app; app = "application/pdf"; File externalDir = Android.OS.Environment.ExternalStorageDirectory; File path = new File(externalDir, "/labs/" + edit.Text + ".pdf"); Android.Net.Uri uri = FileProvider.GetUriForFile(this, "com.companyname.network.provider", path); Intent intent = new Intent(Intent.ActionView); intent.SetDataAndType(uri, app); intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask | ActivityFlags.GrantReadUriPermission); StartActivity(intent);
error in FileProvider.GetUriForFile: Java.Lang.IllegalArgumentException: 'Failed to find configured root that contains /storage/emulated/0/labs/1.pdf'

my manifest:
<?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.network" android:installLocation="auto"> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.companyname.network.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> </provider> </application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> </manifest>

end my file_paths:
<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-files name="external_files" path="."/> </paths>

Tagged:

Best Answer

  • cerioncerion Member ✭✭
    Accepted Answer

    I found the solution, the reason is in file_paths
    <files-path/> --> Context.getFilesDir() <cache-path/> --> Context.getCacheDir() <external-path/> --> Environment.getExternalStorageDirectory(), Context.getExternalFilesDir(String) <external-cache-path/> --> Context.getExternalCacheDir() <external-media-path/> --> Context.getExternalMediaDirs()
    me need external-path

Answers

  • cerioncerion Member ✭✭

    ooops, sorry for code, i dont know, how use forum

  • cerioncerion Member ✭✭

    maybe it's better this way



  • jezhjezh Member, Xamarin Team Xamurai
    edited May 2020

    You can try to modify your file_paths to :

    <?xml version="1.0" encoding="utf-8"?> 
    <paths xmlns:android="http://schemas.android.com/apk/res/android"> 
       <external-path name="external_files" path="/labs"/> 
    </paths>
    
  • cerioncerion Member ✭✭

    jezh, nope, its not work, and "/labs/" too

  • cerioncerion Member ✭✭
    Accepted Answer

    I found the solution, the reason is in file_paths
    <files-path/> --> Context.getFilesDir() <cache-path/> --> Context.getCacheDir() <external-path/> --> Environment.getExternalStorageDirectory(), Context.getExternalFilesDir(String) <external-cache-path/> --> Context.getExternalCacheDir() <external-media-path/> --> Context.getExternalMediaDirs()
    me need external-path

Sign In or Register to comment.