Android Question File.DirRootExternal in Sdkversion 30?

Tjitte Dijkstra

Member
Licensed User
Longtime User
After upgrading to B4a v 11.2 I got the recommendation to change the sdkversion in the Manifest like this: android:targetSdkVersion="30"
I compiled my app and all worked fine.
If File.DirRootexternal was called from the main module it worked, but if File.DirRootexternal was called from a sub-module I got a fatal error: EACCESS(Permission denied)
What to add to the sub modules, or what else?
(If I downgrade to sdkversion 28 the problem is solved as well....)
 

agraham

Expert
Licensed User
Longtime User
java.lang.RuntimeException: Object should first be initialized (TextReader).

That's expected because you can't access that directory targeting SDK 30. We are trying to get it through to you that you need a different structure to your program but we don't seem to be getting anywhere.
 
Upvote 0

Tjitte Dijkstra

Member
Licensed User
Longtime User
java.lang.RuntimeException: Object should first be initialized (TextReader).

That's expected because you can't access that directory targeting SDK 30. We are trying to get it through to you that you need a different structure to your program but we don't seem to be getting anywhere.
Graham, If I quit the possiblity for pupils and teachers to add their own information, the app will be reduced to a "closed box," while by now (since 1992) the app can be used as a topography trainer and a personal archive of small pieces of information.
(It makes not too much use to know where you can find Berlin of London on a map, if you do not train yourself to say in a nutshell what is so specific of these cities. Children love it to write that small additions.)
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I know that is what you want but Android will no longer allow store apps to access the complete file system so you have no option except to work with that if you want the app in the store. You can add the facility to add information by getting the users to create their own folder in external storage using the ExternalStorage class. Perhaps you can work with that.

See this posting about ExternalStorage and folders
 
Upvote 0

Tjitte Dijkstra

Member
Licensed User
Longtime User
I know that is what you want but Android will no longer allow store apps to access the complete file system so you have no option except to work with that if you want the app in the store. You can add the facility to add information by getting the users to create their own folder in external storage using the ExternalStorage class. Perhaps you can work with that.

See this posting about ExternalStorage and folders
I think there are two options left:
1. I read on the site of Google-support that after filling in a form of declaration in which I explain why my app needs specific rights, it might be possible.
2. If the directory that Drgottjr teached me to use, can be filled with pictures and textfiles, why not program a procedure that checks the files in directory ATLAS10 and copies all files to the internal directory and after that delete all the files? I will firts of all do experiments with this option.
Cheers,
TD
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
your problem is 2-fold:
1) decide on the path going forward.
2) figure out a way to migrate your users from 28 to 30. the migratory path(s) put in place by google to facilitate this are no longer applicable.
a) you don't have to copy your user-created content to dirinternal. you only have to copy it to safedirexternal so that they can continue creating content.
b) because you waited until sdk30 (and devices running android 11) were already in place, you are going to find it tricky to accomplish option a.

by the way, throwing yourself on the mercy of google is a option. painting the app as humanitarian could convince them to let you use rootexternal.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Maybe you can post your "fully functional project?"
I have revised and attached my project to use SafeDefaultExternal with SDK target 30, and a device with OS11 because you show interest in GetSafeDirDefaultExternal. The project is based on what you posted a while ago. The 4 files are initially copied from Assets folder to ATLAS10 folder in the SafeDefaultExternal if they do not exist. I assume you know how to add files to the Assets folder via IDE when you start programming, but I added some made up files to the assets folder to represent your files so the app does not crash looking for files. It is fully functional. Please use it as a simple guide to get some ideas, but the final solution is up to you since you know your needs for 30 years. I held off posting the project until I had a feel of your direction.
 

Attachments

  • SDK30WithOS11SafeDefauktExternalMahares.zip
    173.3 KB · Views: 157
Last edited:
Upvote 0

Tjitte Dijkstra

Member
Licensed User
Longtime User
I have revised and attached my project to use SafeDefaultExternal with SDK target 30, and a device with OS11 because you show interest in GetSafeDirDefaultExternal. The project is based on what you posted a while ago. The 4 files are initially copied from Assets folder to ATLAS10 folder in the SafeDefaultExternal if they do not exist. I assume you know how to add files to the Assets folder via IDE when you start programming, but I added some made up files to the assets folder to represent your files so the app does not crash looking for files. It is fully functional. Please use it as a simple guide to get some ideas, but the final solution is up to you since you know your needs for 30 years. I held off posting the project until I had a feel of your direction.
@Mahares,
Thanks for your version of the project. I learned a lot about copying files. Maybe in some other situation I can use this "know how." But in the solution you suggest, the files would be build-in during compilation. That would mean that every time a pupil writes some information (on a city in the register or information about a map) the program would get a new compilation.
Maybe I have to study the possibilities with an extrenal memory-card?
Cheers,
Tjitte Dijkstra, The Netherlands
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
the files would be build-in during compilation. That would mean that every time a pupil writes some information (on a city in the register or information about a map) the program would get a new compilation.
If you expain exactly in detail what you mean by this above sentence, maybe some one would suggest something that is still doable. By the way, I drafted the app based on the project you posted way back in post 12.
 
Upvote 0

Tjitte Dijkstra

Member
Licensed User
Longtime User
Mahares,
If we use the files as File.DirAssets they are part of the in-built information. That means that teachers and pupils have no acces to that information, unless they give it to the programmer who compiles the app! So, first of all I want to study the possibillities of using the extra memory card. If that can be done, the user is free to copy the new information to the memory card.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I am afraid that you did not study the demo program Mahares sent you.
He uses the SafeFolder, which is defined in this line:
SafeFolder = rp.GetSafeDirDefaultExternal("ATLAS10")
And just copied some files from Files.DirAssets to have them in that folder.
This is a special folder accessible from outsides without any permission.
On my device, the folder is: S10 de Klaus\Stockage interne\Android\data\b4a.TestSafeFolder\files\ATLAS10
S10 de Klaus
: the name of my Samsung Galaxy S10
Stockage interne : is the name of the internal memory, in french, yours will be in your language.
Android\data : same for all devices.
b4a.TestSafeFolder : the Package name set in Build Configurations.
ATLAS10 : the subfolder defined in the code above.

I tested this project, I just changed its name from B4A Example to TestSafeFolder and b4x.TestSafeFolder in the Build Configurations.

I can access this folder on the PC with the Widows files explorer connect to the device via a USB cable!

1644495073111.png


I added, on the PC, a new image rose2.jpg and changed this line in the code:
If (File.Exists(SafeFolder,"rose2.jpg")) Then Button1.SetBackgroundImage(LoadBitmap(SafeFolder,"rose2.jpg"))
with the new image file name. And it works !

1644495265242.png


The only drawback is that the folder is on a specific place on the device and it will be removed when you uninstall the program.
The advantage no permission nor user intervention needed.

The only other solution has been explained in previous posts.
 
Upvote 0

Tjitte Dijkstra

Member
Licensed User
Longtime User
@klaus,
Great to read your contribution. Mahares wrote "it is fully functional" and I tried to explain why it is not so functional and a too difficult way. Indeed: the access to the ATLAS10 directory is possible, but only if you know precisely where to go. I guess it is too difficult for children in the age of 10-12 years.
You wrote "The only other solution has been explained in previous posts." I think you refer to (1) not presenting the app in the Play Store or (2) except that this option (let the users add their own information) is not possible anymore. Both would be an unwanted barrière for me.
Merci beaucoup,
(By the way: I'm in study on composing a *.bat file to do the copying of the files from the pc/laptop to the tablet via the path we now know.)
Tjitte Dijkstra, Pays Bas
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Mahares wrote "it is fully functional" and I tried to explain why it is not so functional
By fully functional I meant that it uses target SDK 30, device with OS11 and to write and read from DefaultExternal and it does not crash based on the skeleton project you posted. I cannot tell about your real project because you did not show us anything about it. My conclusion about all this after more than 50 posts is that you are misinterpreting every answer in this thread. It is probably due to language barriers.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Or you could just use Firebase - either create a database using Firestore & share the data that way, or use Storage & upload/download files to/from that.

- Colin.
 
Upvote 0
Top