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.
Related
Hello I am wanting to connect an external GPS unit via I2C or serial to a raspberry pi 3 running android things to have this GPS unit provide location data.
So far using the Rasbarian OS I have a working python script with custom libraries. The script outputs raw NMEA data.
I am wondering how would I need to run this script to be able to have Android Location services use this data for location services? Would I need to create an app using the location services API? Or since this is a locally installed device would I need to write firmware or some kind? I am just wondering if someone could point me in the right direction of what kind of software I would need to write (an app or driver or firmware) in order to have this NMEA data accessible for location services.
Example of GPS driver connected via serial port you can find in Android Things user-space GPS driver and how to use it you can find in UART GPS sample for Android Things. Also take a look at Official Documentation and examples like this.
I have a Google Pixel 3a XL on Android 10 that is unable to make a good Bluetooth serial connection to a Bluetooth SPP module using Bluetooth 2.0. However, I can connect to a module with Bluetooth 1.2. I haven't been able to determine if this is related to all of Android 10, or something specific to the Pixel 3 line.
I'm trying to get GPS position data from a GPS receiver via Bluetooth. When I try to bring up a connection using createInsecureRfcommSocketToServiceRecord(), the serial connection actually comes up for 1-5 seconds. I do get some data from the GPS receiver, however there are chunks missing. Then the data stops flowing. In addition to my app, I have tested this with several other Bluetooth serial terminal programs, and they all have the same results - I get some data, then it stops.
I can use this same Bluetooth module with a different Android device running Android 9 and it works great. I can also connect to this Bluetooth module from Windows and it too works fine.
I have a second Bluetooth module that is older (runs Bluetooth v1.2) and surprisingly it actually works fine with the Pixel.
Has anyone else seen issues with Serial over Bluetooth on Android 10?
Something that changed with Android 10 is that you need to have your location enabled besides the permission in order to connect to some BLE devices. I'm not sure if this will help you, but can give you some light regarding the issue you're having.
"Some telephony, Bluetooth, Wi-Fi APIs require FINE location permission
If your app targets Android 10 or higher, it must have the ACCESS_FINE_LOCATION permission in order to use several methods within the Wi-Fi, Wi-Fi Aware, or Bluetooth APIs. The following sections list the affected classes and methods."
https://developer.android.com/about/versions/10/privacy/changes
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?
I developed an app that work with iBeacons and this week i update it to work on Marshmallow. Until the update it didn't require GPS, but after the update it says that to find beacons in background it need gps. i don't find any reference on it. does someone know why Android Marshmallow requires GPS to find iBeacons?
I use altBeacon library to locate the beacons.
edit:
I'll clarify the question. Is the GPS involved in finding Beacons. Except for the permissions.
No, it is not necessary to have GPS turned on or even have a device with a GPS radio to detect beacons in Android 6. The GPS radio, if present is not activated when scanning for Bluetooth beacons.
The confusion comes from the fact that Android 6 newly requires apps to obtain either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions to be allowed to perform bluetooth scans. This change is simply motivated by informing users that bluetooth scanning can be used to infer their location (like with beacons). But the need to get this permission does not mean there is any technical dependency on the GPS radio. Consider that Android also can use WiFi access points and cell towers to infer location.
On some devices, notably the Nexus 5, there have been reports that disabling Location Services (Settings -> Location -> Off) disables the ability to scan for bluetooth devices. It is unclear whether this is a bug in that Nexus 5 build image or a new security restriction by Android that will be followed on other models in the future. See here for more info. Regardless, having the GPS radio on is not a requirement for Location Services being enabled.
Full disclosure: I am the lead developer on the Android Beacon Library open source project.
from http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html
To access the hardware identifiers of nearby external devices via
Bluetooth and Wi-Fi scans, your app must now have the
ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions:
It's not GPS as such that it needs, but because beacons are a technology that can also pin point your location, the location permission is required.
This is probably a permissions issue. iBeacon uses BT Low Energy, and in Android 6, you need location permission to initiate a scan:
To access the hardware identifiers of nearby external devices via Bluetooth and Wi-Fi scans, your app must now have the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions
Source: Android 6.0 changes
I'm in the middle of building a Wear App for an existing phone app.
We plan on targeting API 23 and modifying our phone app's location permissions to work with Android new runtime permission model (https://developer.android.com/training/permissions/index.html)
I was trying to figure out how the Wearable device running Android 5.0 is going to work once we do that. From what I've learnt when asking for locations for the Wearable from https://developer.android.com/training/articles/wear-location-detection.html:
The wearable may or may not have a GPS radio present. For wearables that do not have a radio, the location data comes from the tethered device.
We don’t need to worry about the source of location data – FusedLocationProvider (as part of the Google Play Service) handles this for you behind the scene.
We are responsible for handling the edge case where the wearable does not have GPS hardware (can be checked via hasSystemFeature()) and if the tethering is interrupted (can be detected via WearableListenerService). An example of this would be when the user goes for a run without the phone. In this case, we are expected to degrade the functionality gracefully.
What’s puzzling me is how this will work when we migrate to the new Marshmallow permission model.
Android Wear is not affected if the hardware has on board GPS since no wear devices run Android 6.0 and the old permission model applies. The problem would come about if a wear device with no GPS hardware is tethered to a device running Android 6.0. In this case, if the wear device requests for the location, it would passed on to the phone and the user has not been asked permission/or has disabled the permission, how will this work at all?
I'm imagining that need to hack around this:
On wearable app start, first check if the hardware has a GPS radio
If no, send a message to the phone to ask if holds the permission for requesting location (use the data sync APIs for this)
If the answer comes back false, then show a message to the user on the wearable and ask if they want to resolve it on the phone.
If the user answers “yes”, push a message to the phone to show an activity where it would just prompt for permission.
Is there a better way to do this?