Android Question New sub folder inside /storage/emulated/0/Android/data/package.name/files

aeric

Expert
Licensed User
Longtime User
When I use the following code:
B4X:
DirTest = rp.GetSafeDirDefaultExternal("Test")

it will create a folder "/storage/emulated/0/Android/data/package.name/files/Test"

Everytime I want to create a new sub folder inside this folder, do I need to write?
B4X:
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
rp.GetSafeDirDefaultExternal("Test/NewSubFolder")

Can't I just use?
B4X:
File.MakeDir(DirTest, "NewSubFolder")

Every time I need to check the permission to use RuntimePermissions (rp) in every Activity when creating new sub folder?
B4X:
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Every time I need to check the permission to use RuntimePermissions (rp) in every Activity when creating new sub folder?
B4X:
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
You don't need permissions for Android 4.4+:

Type of contentAccess methodPermissions neededCan other apps access?Files removed on app uninstall?
App-specific filesFiles meant for your app's use onlyFrom internal storage, getFilesDir() or getCacheDir()

From external storage, getExternalFilesDir() or getExternalCacheDir()
Never needed for internal storage

Not needed for external storage when your app is used on devices that run Android 4.4 (API level 19) or higher
NoYes

- Colin.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I have to use External Storage because it is an old app developed 10 years ago by another company. For the past few years, I just maintain the app as freelance.

Recently I just updated it to support Android 14 which requires new targetSDK 23+.

I can't simply change the app because I am not clear what are the requirements when it was developed. Maybe the files are stored in external storage so users can view them from Android built-in "Files" Explorer app in case there is an issue uploading the files.

The issue occur when the app need to create subfolders based on a different id in runtime.

I just had a meeting at client site just now and convinced them that I would move the files to Internal storage.

After I changed the external storage on last month, there are a lot of issues with the app. I hope using Internal storage could solve all these issues.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
I have to use External Storage because it is an old app developed 10 years ago by another company. For the past few years, I just maintain the app as freelance.

Recently I just updated it to support Android 14 which requires new targetSDK 23+.

I can't simply change the app because I am not clear what are the requirements when it was developed. Maybe the files are stored in external storage so users can view them from Android built-in "Files" Explorer app in case there is an issue uploading the files.

The issue occur when the app need to create subfolders based on a different id in runtime.

I just had a meeting at client site just now and convinced them that I would move the files to Internal storage.

After I changed the external storage on last month, there are a lot of issues with the app. I hope using Internal storage could solve all these issues.
In practical terms there's virtually no difference between external & internal app-specific storage - except that external storage may not be available if it's on removable media. They are both deleted when the app is removed & neither of them require the WRITE_EXTERNAL_STORAGE permission to access.

I must have had similar issues to you in one of my apps at some stage (I can't remember exactly when/what) because I've written a function that checks for external app-specific external dirs & if it finds them, copies them to internal app-specific dirs, then deletes the external ones. I'm not having issues with internal storage, so maybe it'll fix your issues too. :)

- Colin.
 
Upvote 0
Top