Android Question GPS and quick settings screen

JoeR

Member
Licensed User
Longtime User
My app uses the GPS library to test whether GPS is enabled
B4X:
Dim GPS1 As GPS
GPS1.Initialize("")
If GPS1.GPSEnabled = False Then ....
If GPS not enabled, is there a way to enable GPS programmatically, or does this have to be done by the user?

If it has to be done by the user, is there an alternative to the LocationSettingsIntent which produces a "tecchie screen" (1st attachment)?
B4X:
StartActivity(GPS1.LocationSettingsIntent)
For example, is it possible to display the "quick settings screen" (2nd attachment)?
I realise that these screens vary with differing generations/versions of Android but assume that the quick settings screen will always offer a more user-friendly route than the full location and security screen.
Loc and sec.png
quick settings.png
 

rjgoolsby

New Member
Licensed User
Longtime User
Don't know about the screen question but this is from the GPS tutorial:

"Due to privacy concerns the Android OS doesn't allow you to turn the GPS on programatically. The best thing that you can do is to ask the user to enable the GPS device."
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi JoeR,

is this close to what you need?

B4X:
Sub btnGPS_Click
  If Not(GPS1.GPSEnabled) Then
    ToastMessageShow("Please activate GPS", True)
    StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
...

Umberto
 
Upvote 0

JoeR

Member
Licensed User
Longtime User
Thanks for help. The problem is that the screen shown as a result of
LocationSettingsIntent
is somewhat frightening and technical looking (my screenshot shows the location settings screen and the quick settings screen - as they appear on my Samsung phone).

Is there an intent that will display the quick settings screen?

Typical users for my app will be non-technical. For some, my app may be their first use of gps mapping on their phone. This could be the reason why their gps might not be enabled. They might not appreciate how to enable gps or be frightened of enabling it in case it "breaks" their phone.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The quick settings options in the notifications page is unique to Samsung. It is not an Activity by itself.

If you like to open the notifications page then you can use this code, which is based on non-public API:
B4X:
Sub ExpandNotifications
   Dim r As Reflector
   r.Target = r.GetContext
   r.Target = r.RunMethod2("getSystemService", "statusbar", "java.lang.String")
   Dim p As Phone
   If p.SdkVersion >= 17 Then
     r.RunMethod("expandNotificationsPanel")
   Else
     r.RunMethod("expand")
   End If
End Sub

Source: http://stackoverflow.com/questions/...matically-open-close-notifications-in-android

Do note that on most devices there is no GPS option on this "page".
 
Upvote 0

JoeR

Member
Licensed User
Longtime User
Thanks for advice. I want to stick to standard functions. So I will not use the "reflector technique". I will stick to the
LocationSettingsIntent (supported by a clear message to help the user).
 
Upvote 0
Top