Android Question Runtime Permission problem

John Sturt

Active Member
Licensed User
Longtime User
Hello
I have a App that needs the WRITE_SETTINGS permission to work.
How do i RuntimePermissions.checkandrequest it?

Many Thanks
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

John Sturt

Active Member
Licensed User
Longtime User
I have read the tutorial and have added the permission in the manifest due to it
being a non critical one but still get the security error when trying
to set the ringtone.
Am i right in thinking there is no CheckandRequest for WRITE_SETTINGS?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
WRITE_SETTINGS is a special permission: https://developer.android.com/reference/android/Manifest.permission.html#WRITE_SETTINGS

B4X:
Sub Activity_Create(FirstTime As Boolean)
   If CanWrite = False Then
     Dim in As Intent
     in.Initialize("android.settings.action.MANAGE_WRITE_SETTINGS", "")
     StartActivity(in)
   End If
End Sub

Sub Activity_Resume
   Log($"CanWrite: ${CanWrite}"$)
End Sub

Sub CanWrite As Boolean
   Dim p As Phone
   If p.SdkVersion < 23 Then Return True
   Dim ctxt As JavaObject
   ctxt.InitializeContext
   Dim jo As JavaObject
   Return jo.InitializeStatic("android.provider.Settings.System").RunMethod("canWrite", Array(ctxt))
End Sub
Manifest editor:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="23"/>
<supports-screens android:largeScreens="true"
  android:normalScreens="true"
  android:smallScreens="true"
  android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddPermission(android.permission.WRITE_SETTINGS)
 
Upvote 0
Top