diff --git a/android/src/main/kotlin/com/bhikadia/receive_intent/ReceiveIntentPlugin.kt b/android/src/main/kotlin/com/bhikadia/receive_intent/ReceiveIntentPlugin.kt index 993a18f..e7f874e 100644 --- a/android/src/main/kotlin/com/bhikadia/receive_intent/ReceiveIntentPlugin.kt +++ b/android/src/main/kotlin/com/bhikadia/receive_intent/ReceiveIntentPlugin.kt @@ -57,7 +57,7 @@ class ReceiveIntentPlugin : FlutterPlugin, MethodCallHandler, EventChannel.Strea eventSink?.success(latestIntentMap) } - private fun giveResult(result: Result, resultCode: Int?, data: String?) { + private fun giveResult(result: Result, resultCode: Int?, data: String?, shouldFinish: Bool?) { if (resultCode != null) { if (data == null) { activity?.setResult(resultCode) @@ -65,6 +65,9 @@ class ReceiveIntentPlugin : FlutterPlugin, MethodCallHandler, EventChannel.Strea val json = JSONObject(data) activity?.setResult(resultCode, jsonToIntent(json)) } + if(shouldFinish ?: false){ + activity?.finish() + } result.success(null) } result.error("InvalidArg", "resultCode can not be null", null) @@ -87,7 +90,7 @@ class ReceiveIntentPlugin : FlutterPlugin, MethodCallHandler, EventChannel.Strea result.success(initialIntentMap) } "giveResult" -> { - giveResult(result, call.argument("resultCode"), call.argument("data")) + giveResult(result, call.argument("resultCode"), call.argument("data"), call.argument("shouldFinish")) } else -> { result.notImplemented() diff --git a/lib/receive_intent.dart b/lib/receive_intent.dart index d63fa8d..51dd417 100644 --- a/lib/receive_intent.dart +++ b/lib/receive_intent.dart @@ -69,10 +69,11 @@ class ReceiveIntent { .receiveBroadcastStream() .map((event) => ReceivedIntent.fromMap(event as Map?)); - static Future giveResult(int resultCode, {Map? data}) async { + static Future giveResult(int resultCode, {Map? data, bool shouldFinish: false}) async { await _methodChannel.invokeMethod('giveResult', { "resultCode": resultCode, "data": json.encode(data), + "shouldFinish": shouldFinish, }); } }