// 判断是否有locatioin权限
if (!checkLocationPermission()) {
return;
}
// 如果是在搜索的状态,则需要取消搜索
if (bluetoothadapter.isDiscovering()) {
bluetoothadapter.cancelDiscovery();
}
// 搜索蓝牙
bluetoothAdapter.startDiscovery();
// 蓝牙设备广播接收者
private BroadcastReceiver deviceReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent){
String action = intent.getAction();
if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
Log.e(TAG,"开始搜索");
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
Log.e(TAG,"查找到设备完成");
} else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);</