我目前正在设计一款需要连接到设备,写入/读取数据以及可靠地关闭连接的应用。目前我有写/读固体。我断开连接然后重新连接是非常不可靠的,并且经常会使手机崩溃..有时候是Eclipse。我一直在寻找许多文章,试图弄清楚......没有运气..
****连接功能**
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.bIsBTConnected = true;