接上篇,接下来我们就来看一下如何扫描到周围的手机蓝牙,重要是经典蓝牙
// 广播吸收发明蓝牙装备
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
Log.i("Lyb", "开端扫描...");
}
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (device != null) {
if (device.getType() != BluetoothDevice.DEVICE_TYPE_LE)
Log.i("Lyb", "discovery==" + "装备名:" + device.getName() + "\n装备地址:" + device.getAddress());
}
}
if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
Log.i("Lyb", "扫描停止.");
//
}
}
}; // 广播吸收发明