disconnected return

master
张萌 3 years ago
parent 4ba42981ac
commit a642670f57

@ -3,6 +3,8 @@
<component name="ChangeListManager">
<list default="true" id="2f8e3712-04e2-429a-bcea-c8db1a54008e" name="默认变更列表" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/dj/printer/dj_printer/DjPrinterPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/dj/printer/dj_printer/DjPrinterPlugin.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/pubspec.lock" beforeDir="false" afterPath="$PROJECT_DIR$/example/pubspec.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/dj_printer.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/dj_printer.dart" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />

@ -41,7 +41,7 @@ public class Blutooth {
bluetoothPort.SetMacFilter(false);
bluetoothSetup();
searchflags = false;
disconnectflags=false;
disconnectflags = false;
System.out.println("初始化完成");
}
@ -57,12 +57,15 @@ public class Blutooth {
} else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
try {
if (bluetoothPort.isConnected()) {
System.out.println("1111s");
bluetoothPort.disconnect();
}
if ((btThread != null) && (btThread.isAlive())) {
cancelThread();
}
System.out.println("disconnected");
eventSink.success("disconnected");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -160,7 +163,7 @@ public class Blutooth {
try {
bluetoothPort.disconnect();
if((btThread != null) && (btThread.isAlive()))
if ((btThread != null) && (btThread.isAlive()))
btThread.interrupt();
disconnectflags = true;
@ -177,8 +180,11 @@ public class Blutooth {
//取消搜索
public void cancelDiscoveryResult(Context context) {
System.out.println("取消搜索");
mBluetoothAdapter.cancelDiscovery();
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);
}
private class ExcuteDisconnectBT extends AsyncTask<Context, Void, Void>{
private class ExcuteDisconnectBT extends AsyncTask<Context, Void, Void> {
@Override
@ -276,9 +281,8 @@ public class Blutooth {
try {
DisconnectDevice(contexts[0]);
while(true)
{
if(disconnectflags)
while (true) {
if (disconnectflags)
break;
Thread.sleep(100);
@ -291,16 +295,20 @@ public class Blutooth {
}
@Override
protected void onPreExecute(){
protected void onPreExecute() {
super.onPreExecute();
};
}
;
@Override
protected void onPostExecute(Void result){
protected void onPostExecute(Void result) {
disconnectflags = false;
super.onPostExecute(result);
};
}
;
}
}

@ -99,8 +99,12 @@ public class DjPrinterPlugin implements FlutterPlugin, MethodCallHandler {
} else if (call.method.equals("getStatus")) {
int sta = asPrint.Get_Status();
result.success(sta);
} else {
result.notImplemented();
} else if (call.method.equals("disposeDiscovery")) {
blutooth.cancelDiscoveryResult(context);
result.success(true);
} else if (call.method.equals("disposeConnect")) {
blutooth.ExcuteDisconnect(context);
result.success(true);
}
}

@ -102,13 +102,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.2"
meta:
dependency: transitive
description:
@ -211,7 +204,7 @@ packages:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.8"
version: "0.4.3"
typed_data:
dependency: transitive
description:

@ -34,17 +34,16 @@ class DjPrinter {
}
void cancelDiscovery() {
if (_discoveryStream != null) {
_discoveryStream!.cancel();
_discoveryStream?.cancel();
_discoveryStream = null;
}
print('结束搜索');
disposeDiscovery();
}
static const EventChannel _connectChannel = EventChannel("com.connect");
StreamSubscription? _connectStream;
StreamSubscription addConnectListen(
{required void Function() onConnect,
StreamSubscription addConnectListen({required void Function() onConnect,
required void Function() onDisconnect}) {
if (_connectStream == null) {
return _connectChannel.receiveBroadcastStream().listen((data) {
@ -66,9 +65,8 @@ class DjPrinter {
}
}
Future<bool?> get startSearch async {
final res = await _channel.invokeMethod('startSearch');
return res;
void get startSearch {
final res = _channel.invokeMethod('startSearch');
}
Future<bool?> connect(String address) async {
@ -76,6 +74,16 @@ class DjPrinter {
return res;
}
void disposeDiscovery() {
print('disposeDiscovery');
final res = _channel.invokeMethod('disposeDiscovery');
}
Future<bool?> disposeConnect() async {
final res = await _channel.invokeMethod('disposeConnect');
return res;
}
Future<bool?> init() async {
final res = await _channel.invokeMethod('init');
return res;
@ -104,8 +112,7 @@ class DjPrinter {
}
}
Future<bool?> print(
{required String code,
Future<bool?> printAScode({required String code,
required String channel,
required String country,
required String countStr,

Loading…
Cancel
Save