Android Question phone location - a question

kisoft

Well-Known Member
Licensed User
Longtime User
HI
Is it possible to turn on the location on the phone with the help of the code?
can only the user enable the location manually?
 

MarkusR

Well-Known Member
Licensed User
Longtime User
i believe u can only request the location with runtimepermissions and then a os dialog popup if it is disabled.

B4X:
Sub Process_Globals
    Dim rp As RuntimePermissions

B4X:
Sub Activity_Create(FirstTime As Boolean)
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
        
End Sub

B4X:
Sub Activity_PermissionResult(Permission As String, Result As Boolean)

   If Permission = rp.PERMISSION_ACCESS_FINE_LOCATION Then
       CheckBoxGPS.Checked = Result
       If Result = False Then ToastMessageShow("please enable gps + give permissions ...",True)
   End If
  
End Sub
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
it should be possible by code but this would require once a other permission.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
it should be possible by code
i don´t think this is possible.
You probably can send the user to the Settings using an intent. But the user need to enable it.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
it seems every change in location settings result in a user dialog, at least for newer os.
can't found a example to start the location service from code without user interaction.

https://developer.android.com/training/location/change-location-settings

https://developer.android.com/reference/android/location/LocationManager

https://www.mytrendin.com/enable-disable-gps-using-locationmanager/

what DonManfred mentioned
B4X:
Sub Test
    
    Dim StartIntent As Intent
    StartIntent.Initialize("android.settings.LOCATION_SOURCE_SETTINGS", "")
    StartActivity(StartIntent)
    
End Sub
 
Last edited:
Upvote 0
Top