Skip to content

[Android] BackToForeground when app is killed. #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 15 additions & 3 deletions android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down