0

i am creating an app where the user has to posibilty to export certain data to a file (xml) which the user can then use where ever they want.
Now everything worked perfecly fine. the XML content of the file is created, permission asked and even the file is written to de download folder perfecly.
Perfectly in API 28 (Pie) that is. When i started testing in API 33 it all fell apart.
Of course the xml content is still created but the permission..... not to say anything about the actual file writting.

So, web search it was:
developer.android.com
very nich blog by Jerry Hildenbrand
and lots more like this.
The problem is they do not completly answer my questions:

  1. the blog of Jerry states "Scoped Storage gives the ability to create a second folder for files the app creates" can this second folder be accessed by the native file browser? it seems not because later in the text is says my app needs to give permission for that. What is the use of exporting something if you cannot find it then outside of the app?
  2. If you could access the folder in a file browser than how do i get this foldername in my app (kotlin code)?
  3. Is this "second folder" thing backward compatible? (my app targets 24..33)
  4. if this is not the correct way then what is? because even google (first link) say "has no effect" but they do not point to an alternative.

    in short: i am running in circles and am in need of some pointers out of this groundhog day.
Ryan M
  • 18,333
  • 31
  • 67
  • 74
Michel
  • 73
  • 9
  • Related: [Is it possible to programmatically access Download folder on Android Q (SDK >= 29)?](https://stackoverflow.com/q/60415859/295004) – Morrison Chang Apr 18 '23 at 19:08
  • Pretty unclear what goes wrong with writing a file to public Download folder. Every app can do that without any permission on sdk 33. – blackapps Apr 18 '23 at 20:36

1 Answers1

0

I turns out i has nothing to do with the authorizations.
In the continuing search for a solution i found this post link

So, to recap:
What i did is remove my exported files through the device file explorer
After that i tried to recreate them through the app and that failed. I believed it had to do with authorization but it turn out there is some bug in the device file explorer where is seems the file is deleted but there is something left behind that then crashes your app.

To fix this:

  1. i changed the target export names in my app and then exported the files again. as hoped for this worked.
  2. Then through the emulator file explorer (NOT the device file explorer) i renamed the files to the original filenames
  3. Next step (again emulator file explorer: deleted the files.
  4. In my app changed the code to the original export names.
  5. executed the App and test: Succes. all worked again

    So to conclude: do NOT use the device file explorer to delete files!!
Michel
  • 73
  • 9