From 1e8987a5c6100d99c9d4038379e9d967b38a61a2 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Fri, 19 Jun 2020 17:44:56 -0400 Subject: [PATCH 1/2] [Android] backToForeground: allow app to start when killed --- .../io/wazo/callkeep/RNCallKeepModule.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index 77dd4373..25a06261 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -32,6 +32,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.view.WindowManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; @@ -420,11 +421,22 @@ public void backToForeground() { Context context = getAppContext(); String packageName = context.getApplicationContext().getPackageName(); Intent focusIntent = context.getPackageManager().getLaunchIntentForPackage(packageName).cloneFilter(); + Activity activity = getCurrentActivity(); + boolean isOpened = activity != null; + Log.d(TAG, "backToForeground, app isOpened ?" + (isOpened ? "true" : "false")); - focusIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + if (isOpened) { + focusIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + activity.startActivity(focusIntent); + } else { - Activity activity = getCurrentActivity(); - activity.startActivity(focusIntent); + focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK + + WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED + + WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD + + WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); + + getReactApplicationContext().startActivity(focusIntent); + } } private void registerPhoneAccount(Context appContext) { From 2a31f3a600d1be032de14f67162ea18a2d361f66 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Tue, 23 Jun 2020 10:29:14 -0400 Subject: [PATCH 2/2] Document backToForeground --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index f2305377..b76b0722 100644 --- a/README.md +++ b/README.md @@ -386,6 +386,15 @@ const options = { RNCallKeep.hasDefaultPhoneAccount(options); ``` +### backToForeground +_This feature is available only on Android._ + +Use this to display the application in foreground if the application was in background state. +This method will open the application if it was closed. + +```js +RNCallKeep.backToForeground(); +``` ## Events