Detect if GPS receiver is built-in a device

Rick Harris

Well-Known Member
Licensed User
I know how to determine whether a GPS receiver is receiving valid position (lat/lon) data. However, is it also possible to determine whether an Android device has a built-in GPS receiver in the first place? If yes, how?
 

NJDude

Expert
Licensed User
You can use the phone library like this:
B4X:
Dim p As Phone
Dim gps As String

gps = p.GetSettings("location_providers_allowed")

If gps.IndexOf("gps") > -1 Then

   Msgbox("This device has GPS built in", "")
         
Else

   Msgbox("No GPS found", "")
         
End If
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Please

it is possible, that the code for detectin GPS in device work in some device not corectly?

Because in device where is not GPS i get gps.IndexOf("gps")= 0 and not gps.IndexOf("gps")= -1

or it is better to use this code for detecting if GPS is built in?

Sub GPS_GpsStatus (Satellites As List)
If Satellites.IsInitialized Then log("GPS is BUILT IN")
end sub

thank you
p4ppc
 
Last edited:
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Erel, thank for your answer,

but if I understand it good, this not solve the situation.....

I must recognize, if GPS hardware is available in device. IfGPS hardware is available, then I run my function...if GPS is not built in, then I not run my function.....

please, how can I solve this situation?
Thank you
p4ppc
 
Last edited:
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Dear Erel,

thank you very much fo your advice. It give me great direction and its very big help.

Please...I am playing with functions, but in my device :
- is not GPS module
- I am playing with settings of Google location service as TRUE and FALSE
and I get this result

HasFeature("android.hardware.location")) - TRUE
HasFeature("android.hardware.location.gps")) - TRUE (i have not GPS built in)
HasFeature("android.hardware.Location.network")) - FALSE


please what does it mean?
bluetooth, camera and others have good results, only GPS have not good result..

thank you very much
Best regerds
p4ppc
 
Upvote 0
Top