Android Question Permission dialog not showing

Scantech

Well-Known Member
Licensed User
Longtime User
Erel, i had to create this thread. Please test the attach file. This is an example of my project. The write permission dialog will not appear if File.WriteString(File.DirRootExternal, "1.txt", "ttt") is disabled. Try enabling it, then the dialog will appear. This is the strange issue i was experiencing and hopefully there is an explanation for this?

Test with TargetSDKVersion 29 and Android-29
Samsung S10+ with Android 10
 

Attachments

  • Test Permission.zip
    9.2 KB · Views: 161

mcqueccu

Well-Known Member
Licensed User
Longtime User
Note: Dont address question to one person alone in the forum.

Try this. It worked on my Samsung A50 running Android 10

1. I removed the second declaration of Runtime permission in Activity Create
2. Checked for runtime permission result in your initpermission sub
 

Attachments

  • Test Permission2.zip
    9.3 KB · Views: 147
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Note: Dont address question to one person alone in the forum.

Try this. It worked on my Samsung A50 running Android 10

1. I removed the second declaration of Runtime permission in Activity Create
2. Checked for runtime permission result in your initpermission sub

Thanks for testing. Still similar result.

I disabled
B4X:
'        If Result Then
'            Log("permission granted")
'            File.WriteString(File.DirRootExternal, "1.txt", "ttt")
'           
'        End If
B4X:

and the dialog will not appear in Samsung S10+. I did not try it with different device.
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
If you disabled
B4X:
'File.WriteString(File.DirRootExternal, "1.txt", "ttt")
then the IDE will not automatically add Write_external_storage permission. You can click List Permission on the log tab to confirm.

Question: Does it work if that line is not disabled?

Add this to your manifest and try again
B4X:
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Yes, it will work with the lines not disabled. But, it will not work with the lines enabled.

I tested with AddPermission(android.permission.WRITE_EXTERNAL_STORAGE) in manifest and now it works with and without disabling the codes.

I though android.permission.WRITE_EXTERNAL_STORAGE is automatically added?

My question to you. Did the dialog appear without using android.permission.WRITE_EXTERNAL_STORAGE in manifest and the codes disabled?
 
Upvote 0

Geezer

Active Member
Licensed User
Longtime User
If you just want to write to the default external folder, you don't need permissions, or the legacy line in the manifest.

B4X:
Sub Activity_Create(FirstTime As Boolean)   
    InitRuntimePermission
End Sub

Sub InitRuntimePermission
    Dim RE As String = rp.GetSafeDirDefaultExternal( "" )
    File.WriteString( RE, "file.txt", "ttt")
End Sub
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
My question to you. Did the dialog appear without using android.permission.WRITE_EXTERNAL_STORAGE in manifest and the codes disabled?

No, the dialog does not appear. Its expected because you dont need that permission in the first place.
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
If you just want to write to the default external folder, you don't need permissions, or the legacy line in the manifest.

B4X:
Sub Activity_Create(FirstTime As Boolean)  
    InitRuntimePermission
End Sub

Sub InitRuntimePermission
    Dim RE As String = rp.GetSafeDirDefaultExternal( "" )
    File.WriteString( RE, "file.txt", "ttt")
End Sub
Yes, i understand. I was migrating File.DirRootExternal to GetSafeDirDefaultExternal in my app. I created a function to transfer files from File.DirRootExternal to GetSafeDirDefaultExternal. So, i still need that write permission
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Do you think b4a should automatically include android.permission.WRITE_EXTERNAL_STORAGE when using this code rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)?
 
Upvote 0
Top