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. Android程序连接蓝牙设备
- 3. 无法连接2设备蓝牙android
- 4. Android - 蓝牙设备连接广播
- 5. 从Android设备连接到嵌入式蓝牙设备
- 6. 连接到具有蓝牙地址的蓝牙设备
- 7. 列出并连接到蓝牙设备
- 8. 无法连接到蓝牙设备
- 9. IPhone蓝牙连接到非IOS设备
- 10. 发现后我如何连接到蓝牙设备?
- 11. 如何开发可连接到Android和iOS设备的蓝牙设备?
- 12. 如何找到连接的蓝牙设备的蓝牙信号强度
- 13. 如何防止android在蓝牙设备连接时选择蓝牙A2DP路由
- 14. Android:确定蓝牙是否连接到任何设备
- 15. 如何从android连接最近的蓝牙低功耗设备?
- 16. Android Wear无法通过蓝牙连接我的设备
- 17. 连接到蓝牙设备/如何设置RFCOMM能力
- 18. 如何找到连接的蓝牙设备的信号强度
- 19. 在Android 2.1中连接到配对的蓝牙设备(BluetoothSocket)
- 20. 有通过蓝牙连接到Android设备的问题UUID
- 21. 如何编程连接2个Android设备与蓝牙?
- 22. 将蓝牙设备连接到未知设备
- 23. 无法连接蓝牙设备
- 24. 蓝牙连接两个设备(流)
- 25. 蓝牙自动连接配对设备
- 26. Android蓝牙API连接到多个设备
- 27. 使用Android/Java连接到蓝牙设备
- 28. 无法蓝牙键盘连接到Android设备
- 29. 在Android中将多个设备连接到蓝牙
- 30. Android蓝牙API同时连接到多个设备