Android Question Android 11 problem

FerGeoRi

Active Member
Licensed User
Hello everyone.
Another problem, after Android 10, now it's Android 11.
I just found out that my applications that work by reading and writing in text files, do not work anymore in Android 11.
All the changes I apply do nothing.
If anyone has a solution, I'm interested.
Thank you very much in advance.
I'm sorry.
FerGeoRi
 

DonManfred

Expert
Licensed User
Longtime User
Thank you very much in advance.
Where is the small project showing the problem?
Where is the full error if there is one? And i expect there should be one.
Are you using DirRootExternal or DirDefaultExternal?
What is the targetsdk of your app?
Is you app published on Playstore? TargetSDK must be 30 in this case.

start reading here (but i´m pretty sure you already got that link in the past)
 
Last edited:
Upvote 0

FerGeoRi

Active Member
Licensed User
Hello.

Thank you DonManfred for your quick answer.
My application has to read 3 files at startup.
In case they don't exist, I use the instructions below to create them.
And the Access Denied error message appears at the instruction "" LV.TextWriter1.Initialize(File.OpenOutput(Directory01,FileName01,False))

My instructions are:
Repertoire01="/storage/emulated/0/Android/data"
Repertoire02="/storage/emulated/0/Android/data/Sauv"
Repertoire03="/storage/emulated/0/Android/data/b4a.example/MesTel"
LV.TextWriter1.Initialize(File.OpenOutput(Repertoire01,NomFich01,False))
LV.TextWriter1.WriteLine(DateInit1)
LV.TextWriter1.Close
LV.TextWriter1.Initialize(File.OpenOutput(Repertoire02,NomFich02,False))
LV.TextWriter1.WriteLine(DateInit1)
LV.TextWriter1.Close
LV.TextWriter1.Initialize(File.OpenOutput(Repertoire03,NomFich03,False))
LV.TextWriter1.WriteLine(DateInit1)
LV.TextWriter1.Close

My Application is published on playStore.
Here is the Manifeste

'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="30"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:requestLegacyExternalStorage, True)
'End of default text.:

FerGeoRi
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
You will need to restructure your app for Android 11 and later as Google has further restricted access to the file system

This link shows what you can do now.
 
Upvote 1

FerGeoRi

Active Member
Licensed User
Hello to all.
Thank you agraham for your answer.

I finally understood my problem.
My application on PlayStore is in free mode and limited to 8 days.
So at startup this application must read 3 files in the following directories:
- /storage/emulated/0/android/data
- /storage/emulated/0/android/data/Sauv
- /storage/emulated/0/android/data/b4a.example/MesTel

This works fine on SmartPhone up to Android 10.
On Android 11 Smartphone, the application freezes when reading in these directories.

Is there a solution to allow access to these folders?
Thanks in advance.
Thanks in advance.
FerGeoRi
 
Upvote 0

zzb34

New Member
Hello.

Thank you DonManfred for your quick answer.
My application has to read 3 files at startup.
In case they don't exist, I use the instructions below to create them.
And the Access Denied error message appears at the instruction "" LV.TextWriter1.Initialize(File.OpenOutput(Directory01,FileName01,False))

My instructions are:
Repertoire01="/storage/emulated/0/Android/data"
Repertoire02="/storage/emulated/0/Android/data/Sauv"
Repertoire03="/storage/emulated/0/Android/data/b4a.example/MesTel"
LV.TextWriter1.Initialize(File.OpenOutput(Repertoire01,NomFich01,False))
LV.TextWriter1.WriteLine(DateInit1)
LV.TextWriter1.Close
LV.TextWriter1.Initialize(File.OpenOutput(Repertoire02,NomFich02,False))
LV.TextWriter1.WriteLine(DateInit1)
LV.TextWriter1.Close
LV.TextWriter1.Initialize(File.OpenOutput(Repertoire03,NomFich03,False))
LV.TextWriter1.WriteLine(DateInit1)
LV.TextWriter1.Close

My Application is published on playStore.
Here is the Manifeste

'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="30"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:requestLegacyExternalStorage, True)
'End of default text.:

FerGeoRi
this works
thanks
 
Upvote 0

FerGeoRi

Active Member
Licensed User
Good evening to all.
- Thanks for your answer zzb34.
But I don't understand your answer.
- Thanks for your answer Erel.
I already went to Agraham's post but I didn't find the solution.
So I will go back now that you tell me that the solution is in this post.
Sincerely.
FerGeoRi
 
Upvote 0

FerGeoRi

Active Member
Licensed User
Hello everyone and thank you for your help.
I'm sorry but I really need help because I can't really find the solution from the information in your answer.

My application reads a file as follows:
rp.GetSafeDirDefaultExternal("/storage/emulated/0/Android/data" )
DateInit1=File.ReadString("/storage/emulated/0/Android/data" , "/WsMef0.txt")

Otherwise this file is created as follows:
File.WriteString("/storage/emulated/0/Android/data" , "/WsMef0.txt",DateInit1)

These instructions are blocked on Android 11.
Thanks a lot for your help.
FerGeoRi
 
Upvote 0

FerGeoRi

Active Member
Licensed User
Hello and thank you for the answer.
I have made an application in 2 versions, one free and limited to 8 days and the other paid.

When I install the free version, I write this file which contains the date of the installation, if it does not exist.
Each time I activate this free application, I read this file and compare it with the current date of the smartphone.
After 8 days, this application is no longer usable.

I use these directories to avoid that this file is deleted during the uninstallation.

This is to allow the purchase of the application without regret.
Sincerely.
FerGeoRi
 
Last edited:
Upvote 0

FerGeoRi

Active Member
Licensed User
Hello
Many thanks to you Erel.
I'm going to join SaveAs, hoping to succeed given my poor skills.
Thank you very much.
FerGeoRi
 
Upvote 0

FerGeoRi

Active Member
Licensed User
Hello everyone.

After advice to use SaveAs, I downloaded Project.zip.

I have to use MsgBox to understand how it works without success.
I am completely lost.
I don't see where to enter the name of my file nor the target directory.

Clearly I think I'm overwhelmed by this programming method.
It worked fine on Android 10 and 11 does not allow it anymore.
Great!!!

Sincerely
FerGeoRi
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Hello and thank you for the answer.
I have made an application in 2 versions, one free and limited to 8 days and the other paid.

When I install the free version, I write this file which contains the date of the installation, if it does not exist.
Each time I activate this free application, I read this file and compare it with the current date of the smartphone.
After 8 days, this application is no longer usable.

I use these directories to avoid that this file is deleted during the uninstallation.

This is to allow the purchase of the application without regret.
Sincerely.
FerGeoRi
I think you need to change your approach.

You can not use the old method to registration (to save the file without the user select the folder) anymore.

Maybe you could storage the registration information online.
 
Upvote 0

FerGeoRi

Active Member
Licensed User
Hello, and of course thanks for your answers.

I'm using Log as a replacement for MsgBox, but it won't help me in my search for the destination directory and file, since SaveAs doesn't allow it.

I'm not sure if it's a good idea for me to use the same application for all my files, but since Android 11 doesn't allow my application to work anymore, I'm going to revise it and limit its operation.
It was 100% operational but limited to 8 days of operation.
It will be 2% operational without time limit.

And here I am again, thanks to your information.
Thanks again.
Thank you very much.
FerGeoRi

Translated with www.DeepL.com/Translator (free version)
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Here is something that you could think about ...

Your current free starter app is 100% functional. When it is first opened I imagine that it puts a date stamp somewhere. After eight days free use some sort of gate comes down and the user sees a "Trial period expired" notice. Presumably there is a mechanism that prevents them reloading the free version and creating a new date stamp; maybe some collected data gets deleted and this makes the replacement version useless.

What you should think about doing now is, when the gate comes down after eight days allow an in-app payment to release the gate. An in-app payment is a bit more complicated than providing an alternative paid-for app, but it is the way that thousands of apps work.

Sorry if this is useless - without knowing more details about your app it is difficult to be definitive.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
When it is first opened I imagine that it puts a date stamp somewhere.
I think you missed the point by quite a long way! That is what he says his current app does but Android 11 restrictions on access to the file system means he can longer do that in a location that survives de-installation.
 
Upvote 0
Top