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

BluetoothLeScanner on android 6.0.1 (ss s6 edge) cannot found device android >= 6.0.1 #29

Closed
trongkhanh opened this issue Oct 9, 2018 · 3 comments

Comments

@trongkhanh
Copy link

Hi all,
this code for scanning BLE device:

if (mBluetoothLEScanner == null) {
// create bluetoothLE scanner if it is null
mBluetoothLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
}
// start scan bluetooth
mBluetoothLEScanner.startScan(
null,
buildScanSettings(),
mProxyScanCallback);

private ScanSettings buildScanSettings() {
ScanSettings.Builder builder = new ScanSettings.Builder();
builder.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER);
builder.setReportDelay(0);
return builder.build();
}

Setting:



I cannot found device android >= 6.0.1, but can scan other device

There are any problem?Thank you.

@philips77
Copy link
Member

Hi, Since Marshmallow you have to request Location permission (fine or coarse) in order to scan for Bluetooth LE devices. This is a Runtime permission, so you have to ask user to allow.
Check out this link: https://developer.android.com/training/permissions/requesting

Bluetooth LE devices, like beacons, can reveal phone's location. That's why user needs to allow it. Also, on most devices the Location must be enabled in the phone.

@trongkhanh
Copy link
Author

trongkhanh commented Oct 10, 2018

Thanks you for response, philips77. But in AndroidManifest file, i requested Location permission as following:
uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
uses-permission android:name="android.permission.BLUETOOTH" />
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

But App only scan device android < 6.0.1, cannot scan device Sony Xperia Z3 android 6.0.1.

@philips77
Copy link
Member

That's a Runtime permission. You have to request it from the app, not only in the manifest. Read the link i have above.

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

2 participants