Can't create folder in Android 10

I have an application that uses the save function of the drawing component "canvas", as a method to create a folder in the root directory of the mobile.

It has been working well for months, but when I recompiled the application (without having modified anything), it has stopped working on my mobile with Android 10, however when installing the application on another mobile with Android 4.4 it works. I have tried many things to fix it, but there is no way. I really appreciate if someone can help me.

I have created a small application to test the failure separately. Attached screenshots of the blocks.
If you need more information, tell me.

A greeting.

Captura2

On devices with Android ≥ 10, this path points (is redirected) to the ASD (app-specific directory):

See also here (and read the full thread):

1 Like

Thank you very much for your response. Now I can understand where the problem comes from.

The alternative solution is not very clear to me, but I have not managed to create a folder in the root directory with it. If you could explain better how to do it, I would appreciate it.

I need to save the file in a different folder than the one assigned by default, since I need the files to be preserved even if the application is uninstalled.

I have seen that the Kodular canvas does not give me this problem. But I can't import the project in kodular as it is very big and it gives me various errors.

I am waiting for an answer, thank you very much.

you should not create folders anymore in the root directory
use the application specific directory already now to avoid problems in future

use the legacy mode of the file component but be aware, that starting from Android 11 you will not be able to use this anymore, from the release notes

Implement LegacyMode for File component (#2269)

Android 10 uses a new file model that prevents writing to arbitrary locations on external storage (colloquially, /sdcard/). People should migrate their files to app-specific storage, which is what the File component uses by default on Android 10. Checking the LegacyMode option will let you read files in the old locations, but will fail once App Inventor targets Android 11 (summer 2021). This has no effect on Android versions prior to Android 10.

see also

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

Hello, I return to this topic, since I have problems with the "share" component.

The "share" component has not been updated to API 29 in the same way as the "file" component.
This creates problems for me when saving a file and then sharing it, since it does not read the same path with Android ≥10 devices, as Android ≤ 10.

  • One solution would be for the "share" component to point to the ASD (application specific directory), as the "file" component does. (But this should be changed by the appinventor programmers.)

On the other hand, if this is not solved, I need to know how I could identify the Android version of the device, to create solutions by programming based on the version.

  • Postscript: I think it would save problems if the "file" component and other components that have been updated to API 29 work the same way for all versions of Android and all read from the same path.

Thank you very much if someone can help me.

  • I attach some screenshots of how each code currently works with each version of Android:

Prueba2.aia (20.0 KB)

You could use an extension or code like shown here:

which uses an html file in Media as shown.

For a 2.2 emulator, this code returns 2; for an Android tablet 8.1.0 it returns 8 .

The example works and tested on an 2.2 thru Android 8; results might be different on Android 9+AndroidVersion.aia (3.7 KB)

Thank you very much, I will try to program the route according to each version of Android.

I've tried testing it on my Android 10 device and it won't let me install the app.

On a mobile with Android 4.4 the file path directions fail. (In development mode it works for me with the path: file: ///sdcard/AppInventor/assets/deviceVersion.html), in normal mode, I have not been able to find the path of the html file.

I have seen an extension related to this in Taifun's extension directory.

Or if you know to write extensions:

public String ApiVersion(){
  return String.valueOf(Build.VERSION.SDK_INT);
}
2 Likes

I was afraid of that on Android 10. Before packaging the app, use the production path should work.

file:///android_asset/deviceVersion.html . This fails on Android 4.4? and 10? You may still able to get this to work in the compiled app by requesting READ_EXTERNAL_STORAGE Sorry Isaac. I do not have an Android 10 to test. The example builds fine on an Android 8.1; did you change development to false before you attempted to build?

There must be a way to get an Android 10 to read files in the Media.

Try this APK:

It should work on all Android versions.

Blocks

(added to FAQ)

Note that the version number of the current platform can be retrieved by using the PlatformVersion property of the Screen component. This will return the user-facing version number as a string, such as "10.0" or "8.1". This property is available on both Android and iOS.

Thank you very much everyone for your answers.

This is just what I was missing from Anke's comment.

I hope this allows me to fix these issues temporarily.

Could you clarify, which contains the block "replace all text call Taif ..."?

Thank you very much

This is much simpler than using the extension Anke recommended... thanks @ewpatton!

The image is the 2.2 emulator. Tested also on 8.1 Android.

-- Steve

Ohh, I didn't notice that. Thanks.

Does it work on your device?

In Android 10 it works correctly.

But after doing several tests, I see that I can have problems with the previous versions of android 10 if I want to save the files in the root folder of the application.

I cannot save the files in the root directory with the extension "call AplicationSpecificDirectory" from Taifun on a device with Android 4.4.2

I was hoping that these blocks that I attach you save in the file at: /storage/sdcard0/Android/data/appinventor.ai.bulone6868.test/files/a.txt

Captura

But it saves it in:
/storage/sdcard0/storage/emulated/0/Android/data/appinventor.ai.bulone6868.test/files/a.txt

So I think the simplest thing in my case (for now) will be to save the files in the root folder for Devices smaller than Android 10 and in the application folder for those older than Android 10. (In both cases I have created another folder to have the files sorted)

This is how the blocks would be:

Captura3 prueba_version_2.aia (34.2 KB)

Can you think of any other solution?

Thank you very much

Android KitKat has an issue.It takes /storage/sdcard0 as root directory.
Your blocks are correct and will work fine.