Right now I am working on BLE.I found one issue that it's showing me log of startLeScan(): null and scanning also not working I try everything for that and also search about startLeScan(): null but didn't get any solution yet.
Here is my code for BLE connection :
private void scanLeDevice(boolean enable) {
if (enable) {
mBluetoothAdapter.startLeScan(mLeScanCallback);
} else {
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}
And Here is my Log at which i found this thing
01-27 13:12:21.357 4657-4657/com.icuisine D/BluetoothAdapter: stopLeScan()
01-27 13:12:23.003 4657-4657/com.icuisine D/BluetoothAdapter: startLeScan(): null
01-27 13:12:23.004 4657-4657/com.icuisine D/BluetoothAdapter: STATE_ON
01-27 13:12:23.007 4657-4668/com.icuisine D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=5
I go though with lots of websites and found that lesson is now deprecated but don't know how can I get alternate way to do scanning.
I am testing in Nexus 5 Ver Android 6.1 and Also Apply runtime permission for Bluetooth.
I know this is Duplicate question but I didn't found any solution in original one that's why i repost it!
Hope this will be sufficient details. Need Help to do this thing.
Thanks in advance.
BluetoothAdapter.startLeScan is deprecated, may be using BluetoothAdapter.bluetoothLeScanner.startScan solve the problem.
Call below function checkLocationPermission() in your onCreate() of your main activity.
public static final int MY_PERMISSIONS_REQUEST_LOCATION = 99;
public boolean checkLocationPermission() {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.ACCESS_FINE_LOCATION)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
new AlertDialog.Builder(this)
.setTitle(R.string.title_location_permission)
.setMessage(R.string.text_location_permission)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//Prompt the user once explanation has been shown
ActivityCompat.requestPermissions(DeviceControlActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_LOCATION);
}
})
.create()
.show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_LOCATION);
}
return false;
} else {
return true;
}
}
Also Add below permissions in Manifest file.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With