|
|
@ -41,7 +41,7 @@ public class Blutooth {
|
|
|
|
bluetoothPort.SetMacFilter(false);
|
|
|
|
bluetoothPort.SetMacFilter(false);
|
|
|
|
bluetoothSetup();
|
|
|
|
bluetoothSetup();
|
|
|
|
searchflags = false;
|
|
|
|
searchflags = false;
|
|
|
|
disconnectflags=false;
|
|
|
|
disconnectflags = false;
|
|
|
|
System.out.println("初始化完成");
|
|
|
|
System.out.println("初始化完成");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -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();
|
|
|
@ -160,7 +163,7 @@ public class Blutooth {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
bluetoothPort.disconnect();
|
|
|
|
bluetoothPort.disconnect();
|
|
|
|
|
|
|
|
|
|
|
|
if((btThread != null) && (btThread.isAlive()))
|
|
|
|
if ((btThread != null) && (btThread.isAlive()))
|
|
|
|
btThread.interrupt();
|
|
|
|
btThread.interrupt();
|
|
|
|
|
|
|
|
|
|
|
|
disconnectflags = true;
|
|
|
|
disconnectflags = true;
|
|
|
@ -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,12 +269,11 @@ public class Blutooth {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ExcuteDisconnect(Context context)
|
|
|
|
public void ExcuteDisconnect(Context context) {
|
|
|
|
{
|
|
|
|
|
|
|
|
new ExcuteDisconnectBT().execute(context);
|
|
|
|
new ExcuteDisconnectBT().execute(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class ExcuteDisconnectBT extends AsyncTask<Context, Void, Void>{
|
|
|
|
private class ExcuteDisconnectBT extends AsyncTask<Context, Void, Void> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -276,9 +281,8 @@ public class Blutooth {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DisconnectDevice(contexts[0]);
|
|
|
|
DisconnectDevice(contexts[0]);
|
|
|
|
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
while (true) {
|
|
|
|
{
|
|
|
|
if (disconnectflags)
|
|
|
|
if(disconnectflags)
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
Thread.sleep(100);
|
|
|
|
Thread.sleep(100);
|
|
|
@ -291,16 +295,20 @@ 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);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|