|
|
@ -57,12 +57,15 @@ public class Blutooth {
|
|
|
|
} else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
|
|
|
|
} else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (bluetoothPort.isConnected()) {
|
|
|
|
if (bluetoothPort.isConnected()) {
|
|
|
|
|
|
|
|
System.out.println("1111s");
|
|
|
|
bluetoothPort.disconnect();
|
|
|
|
bluetoothPort.disconnect();
|
|
|
|
|
|
|
|
}
|
|
|
|
if ((btThread != null) && (btThread.isAlive())) {
|
|
|
|
if ((btThread != null) && (btThread.isAlive())) {
|
|
|
|
cancelThread();
|
|
|
|
cancelThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("disconnected");
|
|
|
|
eventSink.success("disconnected");
|
|
|
|
eventSink.success("disconnected");
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
@ -177,8 +180,11 @@ public class Blutooth {
|
|
|
|
|
|
|
|
|
|
|
|
//取消搜索
|
|
|
|
//取消搜索
|
|
|
|
public void cancelDiscoveryResult(Context context) {
|
|
|
|
public void cancelDiscoveryResult(Context context) {
|
|
|
|
|
|
|
|
System.out.println("取消搜索");
|
|
|
|
mBluetoothAdapter.cancelDiscovery();
|
|
|
|
mBluetoothAdapter.cancelDiscovery();
|
|
|
|
context.unregisterReceiver(discoveryResult);
|
|
|
|
context.unregisterReceiver(discoveryResult);
|
|
|
|
|
|
|
|
context.unregisterReceiver(searchStart);
|
|
|
|
|
|
|
|
context.unregisterReceiver(searchFinish);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -263,8 +269,7 @@ public class Blutooth {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ExcuteDisconnect(Context context)
|
|
|
|
public void ExcuteDisconnect(Context context) {
|
|
|
|
{
|
|
|
|
|
|
|
|
new ExcuteDisconnectBT().execute(context);
|
|
|
|
new ExcuteDisconnectBT().execute(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -276,8 +281,7 @@ public class Blutooth {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DisconnectDevice(contexts[0]);
|
|
|
|
DisconnectDevice(contexts[0]);
|
|
|
|
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
while (true) {
|
|
|
|
{
|
|
|
|
|
|
|
|
if (disconnectflags)
|
|
|
|
if (disconnectflags)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -293,14 +297,18 @@ public class Blutooth {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onPreExecute() {
|
|
|
|
protected void onPreExecute() {
|
|
|
|
super.onPreExecute();
|
|
|
|
super.onPreExecute();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void result) {
|
|
|
|
protected void onPostExecute(Void result) {
|
|
|
|
disconnectflags = false;
|
|
|
|
disconnectflags = false;
|
|
|
|
super.onPostExecute(result);
|
|
|
|
super.onPostExecute(result);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|