Android Question WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions in Android SDK: 33 (13)

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all

I've a problem.

My app is on Google Play Store uploaded on 03/17 2023. If I install it on my Samsung Android SDK: 33 (13) it installs and works fine.
I'm doing my debugging on my Android LG Android SDK: 29 (10).

But if I do my debugging on Samsung Android SDK: 33 (13) I have a problem with setting permissions.

When I request either of these permissions WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE it fails.

My Confirured Paths (see the screenshot)

My Manifest

B4X:
'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: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="33"/>
<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:usesCleartextTraffic, "true")
SetApplicationAttribute(android:allowBackup, "false")
CreateResourceFromFile(Macro, Themes.LightTheme)
'Non-SSL permission
CreateResourceFromFile(Macro, Core.NetworkClearText)
'End of default text.

AddPermission (android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission (android.permission.READ_EXTERNAL_STORAGE)

'    FusedLocationProvider:

'    required manifest entry required for Google Play Services
AddApplicationText(<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />)
    SetActivityAttribute(MessageDetails, android:windowSoftInputMode, adjustPan|stateHidden)
'Farebase
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile(Macro, FirebaseAnalytics.Crashlytics)


If I don't request these permisions my app works fine on my Samsung. I can use a database file, write to external folder, read fromn this folder and so on.

My question is - why the app installed from the Google play store on my Samsung with WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions works when I requested these permissions but the same app on the same phone doesn't work in debugging?

This is my code for requset permissions



B4X:
Private Sub SetPermission
   
   
    Try
       
        For Each Permission As String In Array(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE,  Starter.rp.PERMISSION_READ_EXTERNAL_STORAGE,  Starter.rp.PERMISSION_ACCESS_FINE_LOCATION, _
            Starter.rp.PERMISSION_RECORD_AUDIO, _
            Starter.rp.PERMISSION_CAMERA)
           
                       
           
            Starter.rp.CheckAndRequest(Permission)
           
            Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
           
            If Result = False Then 'Result is False when I request WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions
                ToastMessageShow("No permission! " & Permission, True)
                           
                Log("No permission! " & Permission)
                MsgboxAsync("Please allow " & Permission & CRLF &"Application will be closed","HCMS")
                Wait For msgbox_result(Res1 As Int)
               
                modFun.ExitApp
                Return
               
            End If
        Next
       
        'we have permission!
        'Do something
       
       
       
    Catch
        Log("SetPermission " & LastException.Message)
        modFun.ShowError("Main_SetPermission " & LastException.Message)
    End Try
   
End Sub

On My LG request of these permissions returns True.
 

Attachments

  • Adroid path.png
    Adroid path.png
    17.9 KB · Views: 107
Last edited:

MicroDrie

Well-Known Member
Licensed User
You may encounter the peculiar Android rule for API 33 that if your app has previously been granted the READ_EXTERNAL_STORAGE permission, then all requested READ_MEDIA_* permissions will be granted for the apps already installed. For the "new version" to debug, add the required new permission(s)
Images and photos: READ_MEDIA_IMAGES
Videos: READ_MEDIA_VIDEO
Audio files: READ_MEDIA_AUDIO
because debug is probably seen as a "new application".
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
You may encounter the peculiar Android rule for API 33 that if your app has previously been granted the READ_EXTERNAL_STORAGE permission, then all requested READ_MEDIA_* permissions will be granted for the apps already installed. For the "new version" to debug, add the required new permission(s)
Images and photos: READ_MEDIA_IMAGES
Videos: READ_MEDIA_VIDEO
Audio files: READ_MEDIA_AUDIO
because debug is probably seen as a "new application".
what if I install the app on a brand new phone for a first time? Because I did the test - on the same phone I deleted the app, previously installed from the Google Play store and installed it again - no problem. Does it still looks like a previously been granted?
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
From about Android API 26, there has been a lot of tinkering with permissions and there were some bug fixes and later adjustments to newer API levels of Android. If you develop software with API 33 and your phone has API 29, things are different. By the way, are you using the latest versions of the B4A-Bridge and the SDK?
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
From about Android API 26, there has been a lot of tinkering with permissions and there were some bug fixes and later adjustments to newer API levels of Android. If you develop software with API 33 and your phone has API 29, things are different. By the way, are you using the latest versions of the B4A-Bridge and the Android SDK Command line tools and the required resources?
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
From about Android API 26, there has been a lot of tinkering with permissions and there were some bug fixes and later adjustments to newer API levels of Android. If you develop software with API 33 and your phone has API 29, things are different. By the way, are you using the latest versions of the B4A-Bridge and the SDK?
IDE 12.50 and Bridge 2.66. Also I'm using latest SDK and Command LIne tools and required resourses with API 33.

This problem is only on my Samsung Android SDK: 33 (13)

See screenshots
 

Attachments

  • b4a.png
    b4a.png
    33.6 KB · Views: 95
  • Screenshot_20230723_142510.jpg
    Screenshot_20230723_142510.jpg
    123.6 KB · Views: 97
Upvote 0

MicroDrie

Well-Known Member
Licensed User
What I have overlooked so far are the used locations on which you have placed your additional libraries.

First, for the Java compiler, you have used the default Window locations, which is read-only for a normal user. Following Erel's advice, I recommend installing Java to C:\Java and not to c:\Program Files\Java\jdk1.8.0_40.
Open a DOS box and run java -version. The result of the latest Qracle 1.8 java version should be:
java version "1.8.0_381"
Java(TM) SE Runtime Environment (build 1.8.0_381-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.381-b09, mixed mode).
Regardless of the result, I advise you to download the latest Java version from Oracle and install it in the current location c:\Program Files\Java\ and after installation copy it completely to the new location C:\Java. Don't forget to set the new location in B4A / B4J.

Second, the location of the additional libraries c:\Program(x86) falls under the Windows access restrictions, so choose another location outside the directories c:\Program Files and c:\Program(x86).

Let us know if the problem persists.

Update: It is no problem at all to have several Java versions next to each other in this way. If you use SLC I advise you to keep using Java 8 for B4A because Java 11 does not produce Doclet files and SLC does not work with Java 14.
 
Last edited:
Upvote 0
Top