radimitrov / CSharpShellApp

77 stars 18 forks source link

Storage access #380

Closed kirk-evans closed 3 weeks ago

kirk-evans commented 1 month ago

Is it possible in a C# Shell program to write a file to some location that is accessible to other apps?

I have a program that writes reports in html (to /reports, but viewing the reports is only possible by using C#Shell's file manager.

I can launch an html viewer, but the folder I'm using is not accessible to the viewer.

IampointZy commented 3 weeks ago

On linux, you can run 'Process.Start("chmod +777 [path]")` to grant read, write and execute permission for all user. On android, this command can be executed and it won't raise exception, but it doesn't work because you have not enough permission to change permission of any file. I guess this html viewer can acess /sdcard/ So you can try to write the .html file under /sdcard/

radimitrov commented 3 weeks ago

Assuming Android 11 storage limitations, you need the "manage_external_storage" permission. The IDE requests this from its file manager dialogs and you can do the same. However it is probably easier to grant it manually from your apps's system settings. Then you can use Android.OS.Environment.ExternalStorageDirectory.AbsolutePath as base directory for example in OpenFileDialog. However regular file access isn't possible for removalable SD card filesystem. This is for device internal storage.

kirk-evans commented 3 weeks ago

Is there any downside to granting that permission? Does that allow other apps to access external storage?

One more vaguely related question. Is the exe that is generated supposed to run on Windows? I tried once and it didn't work. I don't know Android well enough to know if that is the extension for its executables. I tried running it from the C# shell file manager, but I ran into a problem there, too (sorry... I didn't make a note of the error msg.)

radimitrov commented 3 weeks ago

No, it is like any other permission - scoped to the app to which it is granted to. That particular permission basically restores how "WRITE_EXTERNAL_STORAGE" used to work before Android 10. It gives System.IO access to internal storage.