0
A
回答
0
从DOC这里:http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html
要获得BluetoothDevice类,使用BluetoothAdapter.getRemoteDevice(字符串) 创建一个代表一个已知的MAC的设备解决
你以后只需连接就像您通过设备发现检索它一样。
0
我做了这样的:
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice("Some_MAC");
BluetoothSocket tmp = null;
// Get a BluetoothSocket for a connection with the
// given BluetoothDevice
try {
mBluetoothAdapter.cancelDiscovery();
Method getUuidsMethod = BluetoothAdapter.class.getDeclaredMethod("getUuids", null);
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
int sdk = Integer.parseInt(Build.VERSION.SDK);
if(sdk >= 10){
//sdk 2.3?? java.io.IOException: Connection refused
tmp = device.createInsecureRfcommSocketToServiceRecord(uuid);
}else {
tmp = device.createRfcommSocketToServiceRecord(uuid);
}
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(device, 1);
tmp.connect();
} catch (IOException e) {
Log.e(TAG, "failed: ", e);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
相关问题
- 1. Android。连接蓝牙设备
- 2. 连接到蓝牙设备?
- 3. 如何连接到蓝牙a2dp设备?
- 4. Android上的蓝牙 - 如何连接到正确的蓝牙设备?
- 5. Android蓝牙获取连接的设备
- 6. 如何获取Android设备的蓝牙设备连接状态
- 7. Android - 蓝牙设备连接广播
- 8. Android蓝牙连接与串口设备
- 9. Android程序连接蓝牙设备
- 10. 使用蓝牙连接Android设备?
- 11. 无法连接2设备蓝牙android
- 12. 从Android设备连接到嵌入式蓝牙设备
- 13. Android蓝牙连接另一个蓝牙设备
- 14. 如何检查Android设备是否连接到蓝牙鼠标?
- 15. 如何建立RFCOMM蓝牙连接从iOS到Android设备
- 16. Android 4.3:如何连接到多个蓝牙低功耗设备
- 17. 连接到具有蓝牙地址的蓝牙设备
- 18. Iphone蓝牙连接到非IOS设备
- 19. IPhone蓝牙连接到非IOS设备
- 20. java.io.IOException:连接到蓝牙设备时[JSR82]
- 21. 无法连接到蓝牙设备
- 22. 列出并连接到蓝牙设备
- 23. 发现后我如何连接到蓝牙设备?
- 24. 如何开发可连接到Android和iOS设备的蓝牙设备?
- 25. 如何找到连接的蓝牙设备的蓝牙信号强度
- 26. 如何防止android在蓝牙设备连接时选择蓝牙A2DP路由
- 27. Android:如何找出连接的蓝牙设备的名称?
- 28. Android:确定蓝牙是否连接到任何设备
- 29. 如何连接Android中的蓝牙设备
- 30. 如何从android连接最近的蓝牙低功耗设备?