disconnected return

master
张萌 3 years ago
parent 4ba42981ac
commit a642670f57

@ -3,6 +3,8 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="2f8e3712-04e2-429a-bcea-c8db1a54008e" name="默认变更列表" comment=""> <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$/.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" /> <change beforePath="$PROJECT_DIR$/lib/dj_printer.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/dj_printer.dart" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />

@ -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);
}; }
;
} }
} }

@ -99,8 +99,12 @@ public class DjPrinterPlugin implements FlutterPlugin, MethodCallHandler {
} else if (call.method.equals("getStatus")) { } else if (call.method.equals("getStatus")) {
int sta = asPrint.Get_Status(); int sta = asPrint.Get_Status();
result.success(sta); result.success(sta);
} else { } else if (call.method.equals("disposeDiscovery")) {
result.notImplemented(); 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" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.12.11" 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: meta:
dependency: transitive dependency: transitive
description: description:
@ -211,7 +204,7 @@ packages:
name: test_api name: test_api
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.4.8" version: "0.4.3"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:

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

Loading…
Cancel
Save