Android Beacon Library and Update 6.0.1 - android

Yesterday I updated my Samsung Galaxy S5 Neo to the new Android Version 6.0.1. Since then the beacons won't be detected anymore. It does connect the Beacon Service, Updates the scan perios, etc. but it doesn't find any beacons.
Bluetooth is activated and the Beacon scanner of the Beacon Manifacturer still works fine (finds all the beacons). But not my app... It all worked before the new Android Update.

A few things to check:
Verify Location is enabled in Settings -> Location. This must be set to High Accuracy or Battery Saving. If set to Device Only, it won't work. Starting with Android 6, Location must be enabled to do bluetooth scans.
Make sure your app has been granted location permission. Check Settings -> Apps -> Your App -> Permissions, and verify the Location slider is set to on. Starting with Android 6, each app must dynamically request location access at runtime. If your app doesn't have code to do this, you'll need to add it. (Although it is possible to override in settings as described here.)
Make sure your app's manifest declares either FINE_LOCATION or COARSE_LOCATION in its declared permissions.
If the above don't help check LogCat (not just filtering on your application) for bluetooth errors.
See here for more info on the above.

Related

Scan Bluetooth devices in android studio

I try to write a code from documentation but every time it asks for self-check permission and I did not get any device name
Help me to write a code to scan devices in the area
GitHub repositor link for my application
https://github.com/sachinraj0093/BluetoothAttendance/blob/master/app/src/main/java/com/example/bluetoothattendenceapplication/MainActivity.java
If your device running on Android 11 or lower, you need to check the Location is turned on. And in your code, you lack of calling discovery in case !mbluetoothAdapter.isDiscovering().
You can check returned value when call BluetoothAdapter.startDiscovery() to examine the status for start discovery action.

Companion device pairing: Is location services needed to be enabled?

I have implemented Companion device pairing and it works great for most devices without requiring any location permission or location services enabled. However, we found for example Xiaomi Redmi Note 10 Pro (Android 11) where the BLE scan timeouts when Location services are disabled.
Do I still need to implement requiring Location services enabled before the scan or this is undesirable behavior? I hoped it is not needed anymore with this system-level BLE scan.
If so, is there a way how to distinguish which device needs it? I don't want to force all people when it is not needed (for example my Pixel 5)
In my opinion the Companion Device feature was implemented and designed in a rush. You could expect bugs like the "Location services" must be turned on and the Companion Device pairing dialog doesn't warn when it is not enabled. Until Xiaomi or Google fixes this bug, you will need to have workarounds in your app, for example telling the user to first enable Location services if you think that will be needed.
I am also facing issues with applying a scan filter. It is completely a nightmare.
I have started with this:
val filter = ScanFilter.Builder().apply {
setManufacturerData(SOME_INDEX, byteArrayOf(1))
setDeviceName(SOME_NAME)
setServiceUuid(ParcelUuid.fromString(SOME_UUID))
}.build()
Finally, I have only this:
ScanFilter.Builder().apply {
setManufacturerData(SOME_INDEX, byteArrayOf(1))
}.build()
Because setServiceUuid() is not working for example on all tested Huawei phones and Sony Xperia X.
And setDeviceName() is not working for example on Samsung S10e. Finally I have found solution for name filtering by applying directly:
BluetoothLeDeviceFilter.Builder()
.setNamePattern(Pattern.compile(SOME_NAME))
.setScanFilter(filter)

Can't read service messages in Redmi Note 3

Have taken all the necessary permissions for reading SMS in android but app is still not able to detect "service messages" on Redmi Note 3. Is there a special permission in Xiaomi devices to read service messages?
If your phone with API 23 or higher (I think the same should work in lower versions also) goto Settings -> Permissions -> Other Permissions. (be sure that you asked required permissions programmatically if you're targeting API 23 or higher version of Android)
There you can find 2 tabs App and Permissions. Select Permissions tab under that select SMS and MMS option. Now choose your app and Accept/Allow to read Service SMS.
If you're using lower version than 23 use Security app (which is built in app Redmi phones) and there you can find Permissions app for the installed apps.
I am also facing same problem in my Mi Note 3. No apps reading my messages, every time i need to enter OTP.
I think it is good feature from RedMi.
Now I solved this problem with following steps.
Goto Setting->Permissions -> Permissions -> their you select app and accept Read SMS messages

Beacon detection stops when giving ACCESS_FINE_LOCATION permission in Marshmallow

I have set beacon background scan using this tutorial in BaseApplication class but in Marshmallow running device it shows this log:
Caught a RuntimeException from the binder stub implementation.
java.lang.SecurityException: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results
And finally with this and this reference i was able to give location access for Marshmallow running device to detect beacons.
My Problem:
Even when i give Location access it doesn't detect beacons and also stops to show above Log. Is it the problem as in this ISSUE. My Nexus 5 Build number is MRA58N
UPDATE: When i turn on Location manually now it works. But it's strange. Is it right way to detect beacon?
Android Marshmallow introduces an entirely new spin on application permissions,Users now have the ability to revoke runtime permissions whenever they desire. This means that you can’t assume the app has access to the permission, even if it had been granted previously. You can refer this lib or this guide. And you can create a interface listener location changed after enable GPS, when location != 0. After enable GPS you must resume. I Hope this will help you out.

Android 5.0.2 onwards don't allow HID access through Bluetooth LE

My app is working fine, until Android 5.0.2 doesn't allow third party app to connect to HID device over Bluetooth low energy.
myGatt.setCharacteristicNotification(gattChar, true);
06-01 17:39:35.356: W/BluetoothGatt(21599):
java.lang.SecurityException: Need BLUETOOTH_PRIVILEGED permission:Neither
user 10157 nor current process has android.permission.BLUETOOTH_PRIVILEGED.
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
BLUETOOTH_PRIVILEGED permission doesn't work on a third party app. It's only for system or manufacturer apps.
The latest changes from Android note:
Enforce BLUETOOTH_PRIVILEGED permission for HID-over-GATT
https://android.googlesource.com/platform/packages/apps/Bluetooth/+/02bebee
Code snippet:
private static final UUID[] HID_UUIDS = {
UUID.fromString("00002A4A-0000-1000-8000-00805F9B34FB"),
UUID.fromString("00002A4B-0000-1000-8000-00805F9B34FB"),
UUID.fromString("00002A4C-0000-1000-8000-00805F9B34FB"),
UUID.fromString("00002A4D-0000-1000-8000-00805F9B34FB") };
if (isHidUuid(charUuid)) enforcePrivilegedPermission();
My question: is there a way to overwrite HID_UUIDS or enforcePrivilegedPermission? Can I use reflection to by pass it?
Every times Android released a new version, it breaks the previous code.
Thanks!
The question is old, but still worth answering.
The HID (and FIDO https://fidoalliance.org/) service is protected and indeed requires system permission source. Only apps signed with the system key may use this service, that is only Bluetooth settings. This is to ensure that 3rd party apps are not able to listen to keys typed on a wireless keyboards, as all notifications and indications are transferred to all BluetoothGatt objects. Without this protection you would be able to connect to a HID device (you still can), enable notifications using gatt.setCharacteristicNotification(.., true) and receive updates whenever a key is typed. With a bit of knowledge about Report characteristics you can then get all the keys and mouse positions, including passwords, etc. So it's not a break, but a bug fix. On KitKat you still may do this.
The only solution is to compile your own AOSP Android version and sign your app with the same key. Otherwise it would be useless protection.
Btw, starting form Android 8 or perhaps earlier you don't get SecurityException. The call just returns true as if any other and you never get any callback.
This might have been changed here: https://android.googlesource.com/platform/packages/apps/Bluetooth/+/32dc7a6b919375aede777f3c821fa316d85449ae%5E%21/#F2

Categories

Resources