[Android] Add cancel request method (#7)

* feat: add cancel connect for android

* fix: cancel connect only for android

* fix: clean up the project

* chore: new fvm version

* chore: code style and comments

* chore: bump version to 0.0.8
This commit is contained in:
Kseniia Nikitina
2024-05-18 12:34:05 +02:00
committed by GitHub
parent e4a8c2243f
commit 906e87c6a9
11 changed files with 72 additions and 7 deletions
@@ -69,6 +69,16 @@ class NearbyAndroidService extends NearbyService {
return NearbyServiceAndroidPlatform.instance.disconnect();
}
///
/// On [NearbyServiceBusyException] you can check for running jobs
/// (if any of devices has [NearbyDeviceStatus.connecting]).
///
/// If so, call [cancelLastConnectionProcess] to cancel last request
///
Future<bool> cancelLastConnectionProcess() {
return NearbyServiceAndroidPlatform.instance.cancelConnect();
}
///
/// Starts a socket service to transfer data. Uses device with
/// [NearbyCommunicationChannelData.connectedDeviceId].
@@ -55,6 +55,10 @@ abstract class NearbyServiceAndroidPlatform extends PlatformInterface {
throw UnimplementedError('disconnect() has not been implemented.');
}
Future<bool> cancelConnect() {
throw UnimplementedError('cancelConnect() has not been implemented.');
}
Stream<NearbyConnectionAndroidInfo?> getConnectionInfoStream() {
throw UnimplementedError(
'getConnectionInfoStream() has not been implemented.',
@@ -66,6 +66,12 @@ class MethodChannelAndroidNearbyService extends NearbyServiceAndroidPlatform {
return _handleBooleanResult(result);
}
@override
Future<bool> cancelConnect() async {
final result = await methodChannel.invokeMethod("cancelConnect");
return _handleBooleanResult(result);
}
@override
Stream<NearbyConnectionAndroidInfo?> getConnectionInfoStream() {
const connectedDeviceChannel = EventChannel(