0

I'm trying to do:

BluetoothAdapter.getDefaultAdapter().startLeScan()

I've added all required permissions (as I think):

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Please note that Android things does not support the runtime permissions regardless of it is running based on Android 7.0

And what I am getting in the logs:

java.lang.SecurityException: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results

As per documentation, It should be able to start scanning having all that permissions, but for some reason it does not want to.
I am using 0.4.0-devpreview of Android Things on Raspberry Pi 3

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
Vladyslav Matviienko
  • 10,610
  • 4
  • 33
  • 52
  • Did you restart the device after requesting the permissions? or start the app with adb and the `-g` flag? – Blundell May 30 '17 at 12:45
  • @Blundell, there multiple ways to start app from command line, so I'm not sure of which command you are talking about. Can you show an axample? – Vladyslav Matviienko May 30 '17 at 12:59

1 Answers1

5

You need to reboot the device after the app has started to get access to the permissions

Dangerous permissions requested by apps are not granted until the next device reboot. This includes new app installs and new elements in existing apps.

https://developer.android.com/things/preview/releases.html

Another way to force permissions to be given, is to start your app with adb and the -g flag (this will be default in a future version of AndroidStudio)

./gradlew assembleDebug
adb install -g app/build/outputs/apk/app-debug.apk
Blundell
  • 75,855
  • 30
  • 208
  • 233