HOWTO: Get Application Specific Directory -ASD (where one exists) without Extensions

@TIMAI2 might want to edit the subject of this thread and add "only for devices >= Android 10"

1 Like

I linked to this thread from the Files FAQ because of the rich vein of opinions in it. The different considerations are valuable.


I did not understand Replace block, can you explain me ?

It removes the filename, to return the ASD or ROOT DIRECTORY only

my result is a file path, not a folder

Did you set the local variable "file" to "files.png" ?


replacing "dummy.jpg"

If I remember correctly, the ASD only became "a problem" when Android 10 came along. Prior to Android 10, everything was fine and dandy, and the File component, CanvasSaveAs, along with other components, were more than happy saving to the root of the sdcard by default (or the private directory if you left out the slash). There was no ASD as such to worry about before Android 10.

Logic told me that. I therefore came up with a solution that found the ASD if one was supposed to be there (Android 10 +), and if not, to default to the previous location which was the root of the sdcard (especially for the File component). This is where we were saving all our files previous to Android 10. Developers should be comfortable with the default behaviour, not some construct of an ASD when there doesn't need to be one.

With regard to permissions, I have seen several posts in topics on the forum where "power users" recommend the introduction of the file component in order to provide the correct permissions, and we have blocks to request permissions, what the "fear" is of introducing read/write permissions I do not know, the whole point being is that it allows users to read and write to locations in their file system. If the developer needs them to be able to do it, then so be it. I do not believe this "fear" would pass the 5 why test.

This howto was about demonstrating that there were ways of retrieving the application specific directory, if it is there, without the need for an extension, nothing more, and included a logical fallback position if the ASD did not exist (because of Android version).

As mentioned previously, it is my hope that this will all be cleared up soon, and built-in functionality will handle the read/write application areas for App Inventor apps for all versions.

1 Like

there is nothing to worry about... the ASD is very useful and not only for Android >= 10, but also for Android < 10, because all files stored there will be deleted automatically if the app will be uninstalled
As already mentioned earlier by @Anke, your example is only relevant for Android >= 10 devices, so you should add that in the subject to avoid confusion

this is not about the developer, it is about the end user... and usually end users are afraid to grant read/write permission to all files on their device...
therefore obviously the developer is interested in creating an app having as less permissions required as necessary

your example is fine for Android >= 10, @Anke's example is fine for all devices

therefore if the goal is to not use any extensions, I would prefer @Anke's solution, because it works for all Android versions

and actually it is very simple to get the ASD programmatically, here is the source code

  public String ApplicationSpecificDirectory() {
	File file = context.getExternalFilesDir(null); 
	return file.toString();

see also

1 Like

that's a great solution for all Android versions and it could be even better, if you replace the global variables by local variables...


1 Like

Yes OK ...

I'm sorry, I wrote "dummy/jpg"

Or even more compact:


Hi Anke, I can not find Procedure block as your

You will have to make that yourself

1 Like

How can I get the file path for a specific file?

Thank you Peter

Here is the aia: getASD_2.aia (8.6 KB)


1 Like

Thank you @Anke :smile:

1 Like