I want my app to export data to the downloads directory.
To get the downloads directory, I use this code
string path = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath;
path variable has the value
When I save my file to
Path.Combine(path, "myfile.ext"), the file is being saved correctly.
To open that file with my app, I created an Activity
ImportActivity with an attached
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="*" /> <data android:mimeType="*/*" /> <data android:pathPattern="/.*\\.ext" /> <data android:scheme="file" /> <data android:scheme="content" /> </intent-filter>
Now, when I use the file browser (the one from Samsung) and navigate to the downloads directory, I can see my file.
After tapping on said file, my
ImportActivity is being created and I get the file path
When I'm trying to get a corresponding
FileStream, I get an exception that the specified folder can't be found.
That's my first problem.
My second problem is that after just viewing the download folder's content in Windows Explorer or after a device reset, myfile.ext won't be opened with my app. The file association seems to be gone.
How can I solve these problems?