Android Question Incompatibility with Android11

Angelo Maradini

Member
Licensed User
Longtime User
I would like to install in Android 11 an app realized with B4A last year.
When I install the app from apk, I receive a message like this: " This app was built for an older version of Android and may not work properly. Try checking for updates, or contact the developer."
so I set in manifest targetSdkVersion="29"
AddManifestText(<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="29"/> ... )
in this way I could install the app, the message disappears but the app can't run. a white screen appears and disappears suddenly
could someone help me please?
 
Surely it accesses resources that are no longer available on SDK 29 and crashes.

This App maybe accesses the root external memory?
 
Upvote 0
Can you run B4A-Bridge in the phone with Android 11 and run the app in debug mode to check the logs?
 
Upvote 0
In debug I see the wrong line is this:
File.Copy(File.DirAssets, vFileName, File.DirDefaultExternal, vFileName)

I can't copy a file and the error in log is
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.company/files/FileName.db: open failed: ENOENT (No such file or directory)

this happens only in android 11, not in Android 10... :(
 
Upvote 0
 
Upvote 0
File.DirDefaultExternal
Is the problem. You need to request storage permission and add the manifest entry for for targeting SDK 29 which is in the link I gave you above.

Sorry! I sloppily assumed it was File.DirRootExternal instead of reading it carefully.
 
Upvote 0
manifest: check
B4X:
SetApplicationAttribute(android:requestLegacyExternalStorage, true)

AddManifestText(<uses-permission

   android:name="android.permission.WRITE_EXTERNAL_STORAGE"

   android:maxSdkVersion="19" />)

in b4a code check or add
B4X:
    If Sys.SDK>22 Then

        rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
        Wait For Activity_PermissionResult (Permission As String, rresult As Boolean)
        If rresult Then
            .............
            
            End If
        End If

this is working on android11. There are many examples on the forum
 
Upvote 0
File.Copy(File.DirAssets, vFileName, File.DirDefaultExternal, vFileName)
This line:
Code:
File.Copy(File.DirAssets, vFileName, File.DirDefaultExternal, vFileName)
should be:
Code:
File.Copy(File.DirAssets, vFileName, rp.GetSafeDirDefaultExternal(""), vFileName)  'need rp as runtimepermissions lib
It works with SDK 30 and device running OS 11.
i thought copying a file from assets to dirinternal is also not possible with sdk30.
Why are you making such incorrect statement. We are already all confused with all these new permissions maze and you add another cork to it.
 
Upvote 0
Why are you making such incorrect statement. We are already all confused with all these new permissions maze and you add another cork to it.
well i tried it once, and didnt worked on android 11. I couldnt copy a manual into file.internal. So i said "thought".

But to sort things out, i tried it again, and now without issues. Dont know why it didnt worked out first time.
 
Last edited:
Upvote 0
Thanks at all, in particular to Mahares!
I have solved changing
File.DirDefaultExternal
with
rp.GetSafeDirDefaultExternal("")
Good job!!! ;)
 
Upvote 0
Back
Top