Working with GPS via libhardware on Android - android

In AOSP there is libhardare library which contains interface to the GPS driver - gps.h. Using this interface you can get access to GPS driver on low level (C++), turn on GPS and get current location of the device.
On the Internet there are several projects, that use this GPS interface. For example, this one created by kanru. This code works almost perfectly - I could connect to GPS driver and get correct location.
But I ran into a problem. If you turn on GPS driver using kanru project and after awhile turn on GPS via standard method (in GUI), then C++ program will suddenly stop receive information from GPS driver. At the same time in GUI you can see that GPS is On and you can start Google Maps or any other GPS-related application and get your coordinates.
I tried to restart GpsInterface, turn off and on GPS driver via hw_device_t pointer, even restart whole C++ executable - no effect.
After restart of the program GPS driver change status to GPS_STATUS_ENGINE_ON and then - silence.
Also I tried to change the order of actions. I turned on GPS in GUI, launched Google Maps and waited several minutes till I got my location. Then I started my C++ program. It successfully connected to GPS driver and started to get location data. Meanwhile GUI "lost" connection with GPS driver.
I tried to test my program on several devices with Android 4.2 and 5.1 and get same problem on the most of them. Only on Samsung S6 with Android 5.1 my program was able to work perfectly under all conditions.
It seems like on some devices GPS driver configured so that it can work with only one data consumer.
Perhaps someone faced a similar problem?

Related

Codename one - BLE scanning on Android 6 not working

I'm building an app in CN1 that communicates with a BLE device (BlueGiga BLE module). In android 5.0 an CN1 app works as it should. In Android 6 the same app can't find any BLE devices. I can however connect manually to a specific BLE device (device address preset). So the scanning in Android 6 doesn't work.
Based on this I figured out that I need to turn on GPS location and in the source add:
LocationManager locationManager = LocationManager.getLocationManager();
Is this a bug in CN1 or is it a problem in android?
The default scanner in Android 6 (under Settings -> Bluetooth) and the app BlueGiga don't need to turn on GPS location (BlueGiga is written in Android). I also found the app BLE Scanner that does need to turn GPS location. Is it written in CN1?
Why is it necessary to turn on GPS location for BLE scanning to work on devices with Android 6?
The location manager in Android doesn't necessarily map to GPS it maps to "hybrid location" which means it can take location from various sources and combine them into a single location.
I'm not familiar enough with that device but if it provides location it makes sense to "ask for location permissions" which is what we are doing here. As James mentioned in the comments this has nothing to do with the fact that the device is implemented as BLE as that's an external cn1lib and we just invoke the Android API's which abstract that.

Android NETWORK_PROVIDER returns null. Until Phone Restarted

I am finishing an Android application in which I am observing location changes from gps and network providers. My problems is that I have enable both providers properly and I am requesting location updates from each provider. (I am testing on actual phones not a simulator to clarify.) GPS works flawlessly the majority of the time unless I can not get a gps lock(This is expected). I have been racking my brain over why network location are returned null on some phones some of the time and only seem to begin receiving location updates for "network" after phone has been restarted (Not ideal). I have wifi enabled. All the correct permissions Internet,coarse and fine. Gps updates are working just fine. I have tried removing updates from the listener and then requesting again after a set time of receiving null. I have seen this on the S3, One X, galaxy nexus, and a Motorola Droid M. At first I thought it was a hardware issue. Seems like some of the posts out here are related to the same topic. I just want to see if anybody out there has come across a fix or a work around?

Browser geolocation - Android 2.3.4 ignores GPS satellites. How to fix?

Is there a recognized problem with geolocation via the default browser in Android 2.3.4 Gingerbread?
On an HTC G2 android 2.3.4, the default browser does not appear to use the GPS satellites to determine location. As a result, the location the browser sends to the app is off by a mile or so. Yes, the GPS and wi-fi were both on in the phone. We turned wi-fi off and got the same (bad) result.
Is there some voodoo that can be done to get the default browser in 2.3.4 to do proper geolocation?
On an iPhone 3s geolocation with the very same browser app works perfectly. The following link starts the Gmap4 app (I am the developer) and shows your location on the Google 'Hybrid" map:
http://www.mappingsupport.com/p/gmap4.php?mylocation=on
I believe this is not a browser problem, but a phone specific issue. If you are getting a position off by a mile, for sure the position has been acquired from wifi.
When you start the map, it tries to get the LastKnownLocation, and if it's to old it reverts to wifi position. Now, if you turn wifi off, the position acquiried using wi-fi will remain available as a recent LastKnownLocation and will be used to position the map again.
Until you get a better position from GPS this one will be used.
At least some phones discard the LastKnownLocation when you restart them. You can try it, with wifi off, to see what happens.
Regards.

Has NETWORK_PROVIDER behavior changed in Android 4.1.1?

I have an existing well-tested app that utilizes the GPS_PROVIDER and NETWORK_PROVIDER with the same LocationListener.
LocationManager reports gps, network, and passive location providers are available and enabled.
I have recently upgraded my Galaxy Nexus to 4.1.1 and now the NETWORK_PROVIDER does not deliver any location changes. Testing with an Galaxy S III running 4.0.4 works as I am accustomed to, with network location updates coming through, even if WiFi is turned off. When WiFi is turned off, I get the cell tower position.
Talking with colleagues here, I can't rule out some kind of coincidental hardware failure or some sort of default setting change that I haven't found. I've double checked throughout the settings and it appears that everything is properly set.
WiFi is on, Cell network is on, GPS is on, network services are all enabled. I have no GPS signal at my desk, so it's easy to notice when the network location fails to provide a result.
Anyone else running into similar issues with Verizon Galaxy Nexus + 4.1.1, or 4.1.1 and any phone?
As an additional wrinkle, Google Maps is finding my location, but my PASSIVE_PROVIDER is not generating a location either.
The behavior of Android has not changed with regard to the NETWORK_PROVIDER.
I don't know what went wrong or why, but I removed/replaced the battery and SIM card on my Galaxy Nexus and the network provider seems to be providing the correct results.
The lesson for me? Do not assume you will ever get a location reported to your listener, even if you are certain that the network provider is available, enabled and connected.
In my case, I'll need to add another check to make sure my LocationListener does not keep running if I do not get any locations reported.
I have read someone's supposition about this problem.
It is "In some devices if there is no update after request then a network provider do not give a callback".
Consider that possibility.
In my case, I use a getLastKnownLocation() before starting a current location tracking.
Try ctrl+f getLastKnownLocation in this article.

How to send "geo fix" command to real device of Android?

First,thank you for your attention to my question
I'm planning to design an Android GPS locating application
here are my difficulties and situations
(1)my computer hardware has been out of date for a long time and running an android emulator for debugging is really time-costing,thus i bought a real device(android cellphone) one week ago,in the aim of replacing emulator during debugging
(2)i know how to send location datas to an emulator via "DDMS/Emulator Control/Location Controls",but it is disabled for a real device
(3)i am programming indoor,thus using physical gps locating function is not acceptable(even if i turn on "a-gps")
(4)i have found another topic here: Android mock location on device?
however,i can't open the detail links,like "Andrews link"," http://dehuysser.appspot.com/blog/android-developer-shell-released"
I guess these web sites are forbidden by my country......
Here are my questions:
(A)i have found some codes of making mock loation datas ,but these codes can not activate "onLocationChanged" function
However, i wonder if there is a way to send locating datas from PC to real device via USB port(i'm in USB debugging mode), just like sending locations from DDMS to emulator?
(B)i've got the information that, it is possible to send "geo fix" command to emulator as well as to a real device, by "telnet localhost ", but how to check out the port number occupied by my real device?
i know that 5554 port is used for a emulator,but what about the real device?
i've tried to command "netstat" in terminal, but it's a shame to say that i don't know which port is for my android phone......
(C)If my (A)(B) question is not practical,then what's "settings/applications/development/allow mock location" used for?
Please help me, and thank you for your answer!
I have wrote an app exactly for this (this functionality is not available on phones by default) - it's open source and provides exactly the same interface as the emulator (telnet to :5554 and run "geo fix ..." or "geo nmea"): in app store MockGeoFix
The easiest way of using mock data is using the mock test location provider API. It's at the bottom of the documentation page. I've tried it out and location is received in the onLocationChanged callback. Here is some code that you can try out.
The port used by adb is usually 5037.

Categories

Resources