我使用以下接收器来获取周围的蓝牙设备:
// Create a BroadcastReceiver for ACTION_FOUND.
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Discovery has found a device. Get the BluetoothDevice
// object and its info from the Intent.
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String deviceName = device.getName();
String deviceHardwareAddress = device.getAddress(); // MAC address
Log.d(TAG, "Device hardware adress : " + deviceHardwareAddress);
if (deviceName != null){
Log.d(TAG, "Device name : " + deviceName);
if (deviceName.contains("GYDE")){
Log.d(TAG, "Stooping discovery : " + deviceName);
// Don't forget to unregister the ACTION_FOUND receiver.
unregisterReceiver(mReceiver);
}
}
}
}
};
我在该地区有2个蓝牙设备。我看到他们的MAC地址,但他们没有名字。我相信虽然他们有名字,因为:
1)昨天测试时我可以看到它(从那时起没有任何修改)
2)启用蓝牙后,我的手机可以列出他们的名字
3)我实际上可以看到我的电话名称