'Cannot scan any bluetooth device on all Android versions
I'm working on A2DP and GAT bluetooth profile. I need get all available A2DP bluetooth devices around bluetooth application.
However, I didn't scan any low energy bluetooth device or classic bluetooth device by using startDiscovery() or startLeScan() API so far.
I set enough permission in the Android Manifest file as below:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
I also pulled and run Google's origin sample:
https://github.com/android/connectivity-samples/tree/master/BluetoothLeGatt
But, it didn't work
Here is my code by using startDiscovery API
public void searchDevices(OnSearchDeviceListener listener) {
checkNotNull(listener);
if (mBondedList == null) mBondedList = new ArrayList<>();
if (mNewList == null) mNewList = new ArrayList<>();
mOnSearchDeviceListener = listener;
if (mBluetoothAdapter == null) {
mOnSearchDeviceListener.onError(new NullPointerException(DEVICE_HAS_NOT_BLUETOOTH_MODULE));
return;
}
if (mReceiver == null) mReceiver = new Receiver();
// ACTION_FOUND
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
mContext.registerReceiver(mReceiver, filter);
// ACTION_DISCOVERY_FINISHED
filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
mContext.registerReceiver(mReceiver, filter);
mNeed2unRegister = true;
mBondedList.clear();
mNewList.clear();
if (mBluetoothAdapter.isDiscovering())
mBluetoothAdapter.cancelDiscovery();
mBluetoothAdapter.startDiscovery();
if (mOnSearchDeviceListener != null)
mOnSearchDeviceListener.onStartDiscovery();
}
I'm not sure, Has the Google updated the bluetooth framework?
If anybody know this issue, please help me. Thank in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
