Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan in Android 6.0 #204

Closed
randdusing opened this issue Nov 10, 2015 · 15 comments
Closed

Scan in Android 6.0 #204

randdusing opened this issue Nov 10, 2015 · 15 comments

Comments

@randdusing
Copy link
Owner

There are some permission changes with Android 6.0 that seem to be causing scans to not work. I'm working on an update that should hopefully fix the issue.

@randdusing
Copy link
Owner Author

After doing some research, scanning for Bluetooth device's on Android 6.0 seems to require the Coarse Location permission. I modified the code to request for permission, but it's a little 'scary' looking to the average user since it asks "Allow {{appName}} to access this device's location?" If the user clicks deny, the error callback will return with an error named 'permissions'. You can use this to explain to the user why you're requesting permissions. I have a feeling this prompt will increase the number of support tickets I receive and decrease my ratings. :(

By the way, if the user has paired the device and you use retrieveConnected, the coarse location permissions aren't needed.

I also checked out the BluetoothLeScanner class introduced in API 21, but it requires coarse location permissions as well. Since API 21 and 22 don't request permissions at runtime, I'd need to add the Coarse Location permission to plugin.xml. I'll probably hold off on implementing this until I better understand the permissions impact.

@agoransson
Copy link

I've tried adding the permissions (BT, BTAdmin, Coarse) to both Manifest and plugin.xml, but it doesn't have any effect.

@randdusing
Copy link
Owner Author

Yah, even if you specify the permissions you still need to request to actually use them. Give me a few minutes and I'll have a dev branch with the changes.

@randdusing
Copy link
Owner Author

@randdusing
Copy link
Owner Author

@agoransson You'll need to update to the latest Android Cordova version 5.0.0. I'm seeing if I can enforce that via the plugin.xml

@agoransson
Copy link

I found some more information now.

11-10 20:37:57.487  3604  3604 I chromium: [INFO:CONSOLE(177)] "Is Initialized", source: file:///android_asset/www/js/controllers.js (177)
11-10 20:37:57.590  3604  3604 I chromium: [INFO:CONSOLE(13)] "Uncaught TypeError: Cannot read property 'Keyboard' of undefined", source: file:///android_asset/www/js/app.js (13)
11-10 20:37:57.613  3604  3604 I chromium: [INFO:CONSOLE(183)] "Is Initialized Success : {"isInitialized":false}", source: file:///android_asset/www/js/controllers.js (183)
11-10 20:37:57.613  3604  3604 I chromium: [INFO:CONSOLE(191)] "Is Initialized : false", source: file:///android_asset/www/js/controllers.js (191)
11-10 20:37:57.653  3604  3604 I chromium: [INFO:CONSOLE(177)] "Is Initialized", source: file:///android_asset/www/js/controllers.js (177)
11-10 20:37:57.711  3604  3604 I chromium: [INFO:CONSOLE(183)] "Is Initialized Success : {"isInitialized":false}", source: file:///android_asset/www/js/controllers.js (183)
11-10 20:37:57.712  3604  3604 I chromium: [INFO:CONSOLE(191)] "Is Initialized : false", source: file:///android_asset/www/js/controllers.js (191)
11-10 20:37:58.751  3604  3604 I chromium: [INFO:CONSOLE(0)] "'Touch.webkitRadiusX' is deprecated and will be removed in M47, around November 2015. Please use 'Touch.radiusX' instead.", source:  (0)
11-10 20:37:58.752  3604  3604 I chromium: [INFO:CONSOLE(0)] "'Touch.webkitRadiusY' is deprecated and will be removed in M47, around November 2015. Please use 'Touch.radiusY' instead.", source:  (0)
11-10 20:37:58.753  3604  3604 I chromium: [INFO:CONSOLE(0)] "'Touch.webkitRotationAngle' is deprecated and will be removed in M47, around November 2015. Please use 'Touch.rotationAngle' instead.", source:  (0)
11-10 20:37:58.753  3604  3604 I chromium: [INFO:CONSOLE(0)] "'Touch.webkitForce' is deprecated and will be removed in M47, around November 2015. Please use 'Touch.force' instead.", source:  (0)
11-10 20:37:58.770  3604  3604 I chromium: [INFO:CONSOLE(33)] "Initialize : {"request":true}", source: file:///android_asset/www/js/controllers.js (33)
11-10 20:37:58.799  3604  3604 I chromium: [INFO:CONSOLE(39)] "Initialize Success : {"status":"enabled"}", source: file:///android_asset/www/js/controllers.js (39)
11-10 20:37:58.799  3604  3604 I chromium: [INFO:CONSOLE(43)] "Enabled", source: file:///android_asset/www/js/controllers.js (43)
11-10 20:37:58.817   799  1507 I ActivityManager: Killing 2810:se.fskab.android.reseplaneraren/u0a95 (adj 15): empty #17
11-10 20:38:04.376  3604  3604 I chromium: [INFO:CONSOLE(104)] "Start Scan : {"serviceUuids":[],"allowDuplicates":false}", source: file:///android_asset/www/js/controllers.js (104)
11-10 20:38:04.383  3604  3686 D BluetoothAdapter: startLeScan(): null
11-10 20:38:04.389  3604  3686 D BluetoothAdapter: STATE_ON
11-10 20:38:04.397   392   417 D BtGatt.GattService: registerClient() - UUID=0fb3e5f1-9978-401a-831b-95a2d310662c
11-10 20:38:04.413   392   440 D BtGatt.GattService: onClientRegistered() - UUID=0fb3e5f1-9978-401a-831b-95a2d310662c, clientIf=5
11-10 20:38:04.413  3604  3616 D BluetoothLeScanner: onClientRegistered() - status=0 clientIf=5
11-10 20:38:04.413   392   547 D BtGatt.GattService: start scan with filters
11-10 20:38:04.415   392   445 D BtGatt.ScanManager: handling starting scan
11-10 20:38:04.416   392   445 D BtGatt.ScanManager: configureRegularScanParams() - queue=1
11-10 20:38:04.416   392   445 D BtGatt.ScanManager: configureRegularScanParams() - ScanSetting Scan mode=2 mLastConfiguredScanSetting=-2147483648
11-10 20:38:04.416   392   445 D BtGatt.ScanManager: configureRegularScanParams - scanInterval = 8000configureRegularScanParams - scanWindow = 8000
11-10 20:38:04.416   392   440 D BtGatt.GattService: onScanParamSetupCompleted : 0
11-10 20:38:04.418  3604  3604 I chromium: [INFO:CONSOLE(110)] "Start Scan Success : {"status":"scanStarted"}", source: file:///android_asset/www/js/controllers.js (110)
11-10 20:38:04.420  3604  3604 I chromium: [INFO:CONSOLE(120)] "Scan Started", source: file:///android_asset/www/js/controllers.js (120)
11-10 20:38:08.301   392   440 D bt_btif_gattc: btif_gattc_update_properties BLE device name=SensorTag len=9 dev_type=2

Still not firing the onLeScan callback.

@randdusing
Copy link
Owner Author

It shouldn't be an issue. I believe it just means no service UUIDs are used for filtering.

Are you getting a permissions prompt at all? Since it doesn't seem to be calling the onLeScan callback, it must be getting stopped at a lower level somewhere.

What's your javascript code look like?

@agoransson
Copy link

No permission prompt at all.

I'm using https://github.com/randdusing/ng-cordova-bluetoothle - the only modification is multiple controller and template files.

@randdusing
Copy link
Owner Author

Are you sure you're using recently published code?

@agoransson
Copy link

Yep, installed with ionic plugin add https://github.com/randdusing/BluetoothLE.git#2.5.0 seems to be the correct version installed.

@randdusing
Copy link
Owner Author

Ahh, can you check the app settings? Maybe the location permission is already set to yes. But that leads us back to the original problem.

@agoransson
Copy link

Hmm. Found it.

Had to enable "Location" in the device settings - see this thread on stackoverflow http://stackoverflow.com/questions/33043582/bluetooth-low-energy-startscan-on-android-6-0-does-not-find-devices

Getting all sorts of of scan results now.

@randdusing
Copy link
Owner Author

Interesting that it never prompted you for the permission, that's what it should have done... Glad it's working either way though!

@elafargue
Copy link

My 2 cents: many apps use BTLE to actually acquire coarse location by relying on known bluetooth Beacons... so in a way, this makes sense from a user information standpoint. Not very fair to apps that use BTLE for more worthy usage...

@randdusing
Copy link
Owner Author

Yep, at first I was annoyed, but I understand the permission requirement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants