Open KieranDevvs opened 2 years ago
I see you mention preview 13 as the affected version. Could you please update to the latest version RC1 and try again?
Hi @KieranDevvs. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
I see you mention preview 13 as the affected version. Could you please update to the latest version RC1 and try again?
The issue is still present on RC1. The application has the correct permissions as prior to testing the RC1 Storage API, I called the Android API which worked.
Hi KieranDevvs I watched your issue of https://github.com/dotnet/maui/discussions/6004 and this,I don't get the point of you question. Is it the api said can manage all files ,but now still just copy the file of you FilePicker picked to /cache path right? If so,I have same issue.Would you might to tell me that did you fix this issue on your project?and how? Thank you
Hi KieranDevvs I watched your issue of #6004 and this,I don't get the point of you question. Is it the api said can manage all files ,but now still just copy the file of you FilePicker picked to /cache path right? If so,I have same issue.Would you might to tell me that did you fix this issue on your project?and how? Thank you
MAUI has its own helper library called essentials
that provides a wrapper api around each platform.
For example, without the essentials library, you would have to handle the logic of reading and writing files from persistent storage on both iOS and Android separately because they both have differing implementation details.
The Android API has changed in recent versions so that applications can no longer access files outside of their own domain however, there are some applications that need the functionality to access files outside of their application domain thus the later versions of the Android API have included the MANAGE_EXTERNAL_STORAGE permission so that they can request the user authorize this behaviour on their device.
The issue I have raised is referring to the problem that the essentials file manager API does not take into account this new permission and thus there is no way to obtain this behaviour on Android while using the essentials library.
My work around is to call the Android API explicitly (rather than calling the essentials
api) as shown in the screenshots:
Thank you for your explain about this permision issue! I'll tried to do on my Project ,Thank you again!
repro with vs main build(32621.322)
repro with vs main build(32621.322)
Can you also confirm your android app has MANAGE_EXTERNAL_STORAGE when reproducing, as the cached values are valid under scenarios where apps only have access to their app domain.
You may need to enable it via Android settings as I've had issues getting the app to request this permission automatically:
yes, I have enabled it in emulator
yes, I have enabled it in emulator
Thanks.
Hi there, I have same problem. The filepicker returns the path to cached file. I read your conversation, but I wasn't able to find solution. It has same behavior on the real phone. Can somebody show me, how to get it work?
Hi there, I have same problem. The filepicker returns the path to cached file. I read your conversation, but I wasn't able to find solution. It has same behavior on the real phone. Can somebody show me, how to get it work?
Youre basically just calling the android API wrappers directly, rather than calling the essentials API. This does mean that you'll have to write platform specific code to deal with file handling.
1) Start an activity with the intent to select a file (this will tell the android OS to prompt the user with a native file selection window).
2) Have your application deal with the activity callback (this is triggered when the user has selected a file in the native file browser). Each activity has a request code / identifier so the consumer knows how to deal with the callback. (I wouldnt use this code in production but it gives you an idea on how to get it to work)
3) Unfortunately the intent data isnt readable by default as it has an android specific format. I found this helper class from another project that helps you convert it to a usable file path that you can use with System.IO
.
4) once you have the actual file path (that is not cached), you can just use System.IO.File.ReadAllTextAsync(...)
/System.IO.File.WriteAllTextAsync(...)
, assuming that the application has the necessary android permissions to read/write to the file.
Hope that helps.
Hi Kieran, thank you a lot for rich explanation. It'll take me some time to consume it. But I beleive, that I'll manage it.
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
Try it !
var docsDirectory = Android.App.Application.Context.GetExternalFilesDir(Android.OS.Environment.DirectoryDocuments); File.WriteAllText($"{docsDirectory.AbsoluteFile.Path}/atextfile.txt", "contents are here");
I'm not sure what your comment has to do with this issue?
Is there any update on this?
This is a massive pain at the moment.
@KieranDevvs, I was trying your workaround and in step # 1 currentActivity.StartActivity(permissionIntent);
I am getting this error
Android.Content.ActivityNotFoundException: 'No Activity found to handle Intent { act=android.settings.MANAGE_ALL_FILES_ACCESS_PERMISSION dat=package:com.XX.TestReader }'
I am invoking FileSelector.SelectAsync()
from one of my UI pages. Can you please help with this, or if there is any sample app you may have that I can refer to?
@KieranDevvs, I was trying your workaround and in step # 1
currentActivity.StartActivity(permissionIntent);
I am getting this error
Android.Content.ActivityNotFoundException: 'No Activity found to handle Intent { act=android.settings.MANAGE_ALL_FILES_ACCESS_PERMISSION dat=package:com.XX.TestReader }'
I am invoking
FileSelector.SelectAsync()
from one of my UI pages. Can you please help with this, or if there is any sample app you may have that I can refer to?
@ac-lap Hope this helps: https://github.com/KieranDevvs/FilePickerIssueWorkaround
You can message me on discord if you have any issues: KieranDevvs#5374
@KieranDevvs, I was trying your workaround and in step # 1
currentActivity.StartActivity(permissionIntent);
I am getting this errorAndroid.Content.ActivityNotFoundException: 'No Activity found to handle Intent { act=android.settings.MANAGE_ALL_FILES_ACCESS_PERMISSION dat=package:com.XX.TestReader }'
I am invokingFileSelector.SelectAsync()
from one of my UI pages. Can you please help with this, or if there is any sample app you may have that I can refer to?@ac-lap Hope this helps: https://github.com/KieranDevvs/FilePickerIssueWorkaround
You can message me on discord if you have any issues:
KieranDevvs#5374
Great, Thanks
So this issue is Backlogged?? Any update on a real resolution? This sounds like a MAJOR HEADACHE in adopting MAUI for production with any type of app that requires extensive file system use. I'm not understanding why this issue is not a Priority? Is the workaround still the only solution?
So this issue is Backlogged?? Any update on a real resolution? This sounds like a MAJOR HEADACHE in adopting MAUI for production with any type of app that requires extensive file system use. I'm not understanding why this issue is not a Priority? Is the workaround still the only solution?
A lot of us are just dropping down an API. Instead of using API 33, use API 32 and use the old storage permissions. Still works on 33 (for now).
So this issue is Backlogged?? Any update on a real resolution? This sounds like a MAJOR HEADACHE in adopting MAUI for production with any type of app that requires extensive file system use. I'm not understanding why this issue is not a Priority? Is the workaround still the only solution?
This problem is split into two parts. 1) Android now require applciations who want to manage files, to explicitly request that permission from the user. 2) MAUI's API wrapper doesn't care if an app is given permission, it will always use the cached app domain for its storage scope.
The point im making is that even if you ditch MAUI, you still have to adopt the same process regardless of what framework / language you use. It would just be nice for the developer if MAUI can actually get its API wrappers to work properly so more boilerplate doesn't have to be written.
A lot of us are just dropping down an API. Instead of using API 33, use API 32 and use the old storage permissions. Still works on 33 (for now).
This is a restriction implemented in Android 10 (API level 29) https://developer.android.com/training/data-storage/app-specific
On devices that run Android 9 (API level 28) or lower, your app can access the app-specific files that belong to other apps, provided that your app has the appropriate storage permissions. To give users more control over their files and to limit file clutter, apps that target Android 10 (API level 29) and higher are given scoped access into external storage, or scoped storage, by default. When scoped storage is enabled, apps cannot access the app-specific directories that belong to other apps.
Verified this issue with Visual Studio Enterprise 17.9.0 Preview 2. Can repro this issue.
Description
When using
FilePicker
with the permissions: https://developer.android.com/training/data-storage/manage-all-files, I still get a cached file copy rather than the original file path.My use case is that I am building a document editor and need an easy way to read and write files anywhere on the device file system.
My original issue that this stems from: https://github.com/dotnet/maui/issues/4195 My work around: https://github.com/dotnet/maui/discussions/6004
Steps to Reproduce
Give your application MANAGE_EXTERNAL_STORAGE permissions, as well as special intent: ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION by going into Android settings -> Application Permissions -> Special App Access -> All Files Access -> Enable
Then open the
MAUI.Essentials.FilePicker
and select a file. The file path returned will be a cached copy.Version with bug
RC1
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 11 - API 30
Did you find any workaround?
I have managed to work around the issue by creating platform specific file handling, and on android, Im calling the android API directly:
And then using the
System.IO.File
API to write data back to the path returned by the android file select activity.Relevant log output
No response