我目前正在设计一个应用程序,它需要连接到设备,写入/读取数据,并可靠地关闭连接。目前我有写/读固体。我的断开连接然后重新连接非常不可靠,并且经常实际上使手机崩溃。我一直在寻找通过大量文章试图弄清楚和..没有运气..Android蓝牙:连接()/断开()
****连接功能**
public boolean connect()
{
ConfigData.getInstance();
BluetoothSocket tmp = null;
BluetoothDevice device = ConfigData.m_SharedBluetoothDevice;
Method m;
try {
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);//(BluetoothSocket)
m.invoke(device, 1);
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
ConfigData.m_SharedBluetoothSocket = tmp;
try {
ConfigData.m_SharedBluetoothSocket.connect();
ConfigData.bIsBTCon