From b09080e5ed1e0fde09b64c006a3648f818240986 Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Thu, 7 Jan 2021 23:18:18 +0800 Subject: [PATCH] Fix backToForeground method. --- .../main/java/io/wazo/callkeep/CallKeepModule.java | 11 +++++++---- lib/src/api.dart | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/io/wazo/callkeep/CallKeepModule.java b/android/src/main/java/io/wazo/callkeep/CallKeepModule.java index 31fe6ef..c4773ad 100644 --- a/android/src/main/java/io/wazo/callkeep/CallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/CallKeepModule.java @@ -544,7 +544,7 @@ public static Boolean isConnectionServiceAvailable() { @SuppressLint("WrongConstant") public void backToForeground(@NonNull MethodChannel.Result result) { Context context = getAppContext(); - String packageName = context.getApplicationContext().getPackageName(); + String packageName = context.getPackageName(); Intent focusIntent = context.getPackageManager().getLaunchIntentForPackage(packageName).cloneFilter(); Activity activity = this._currentActivity; boolean isOpened = activity != null; @@ -557,10 +557,13 @@ public void backToForeground(@NonNull MethodChannel.Result result) { WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED + WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD + WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); - - this._currentActivity.startActivity(focusIntent); + if (activity != null) { + activity.startActivity(focusIntent); + } else { + context.startActivity(focusIntent); + } } - result.success(null); + result.success(isOpened); } private void initializeTelecomManager() { diff --git a/lib/src/api.dart b/lib/src/api.dart index 8ddbe3d..209c3f2 100644 --- a/lib/src/api.dart +++ b/lib/src/api.dart @@ -253,10 +253,11 @@ class FlutterCallkeep extends EventManager { Future backToForeground() async { if (isIOS) { - return; + return false; } - await _channel.invokeMethod('backToForeground', {}); + return await _channel + .invokeMethod('backToForeground', {}); } Future _setupIOS(Map options) async {