【发布时间】:2014-01-13 17:47:28
【问题描述】:
我正在使用蓝牙控制家用设备的应用程序,我的应用程序将在其中连接并需要与我的 HC-05 蓝牙模块配对,但问题是当我编写了一些代码以捕获除 20:13 之外的其他 MAC 地址时: 06:19:34:00 这是 HC-05 蓝牙模块的 MAC 地址,它会捕获包括我的 HC-05 在内的所有蓝牙设备,我在代码中特别包含了它的 MAC 地址。
所以这是我捕获mac地址的部分:
case REQUEST_DEVICE_CONNECT:
String HC05 = "4C:0F:6E:0F:12:F4";
// When DeviceList Activity returns with a device to connect
if (resultCode == Activity.RESULT_OK) {
// Get the device MAC address
//String address = data.getExtras().getString(DeviceList.EXTRA_DEVICE_MAC_ADDRESS);
String address = new String(data.getExtras().getString(DeviceList.EXTRA_DEVICE_MAC_ADDRESS));
if (address == HC05)
{
// Get the BLuetoothDevice object
BluetoothDevice device = BTAdapter.getRemoteDevice(address);
// Attempt to connect to the device
commandService.connect(device);
}
else if (address != HC05)
{
Toast.makeText(this, "This device is not for JavaC101 Application. Please connect to HC-05 device.", Toast.LENGTH_LONG).show();
}
}
break;
我已经尝试了其他一些可能性,但我仍然无法使用此功能。无论如何,它是我第一次创建一个 android 应用程序。任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: java bluetooth comparison-operators