Skip to content

Commit bedfc23

Browse files
authored
Merge pull request #223 from react-native-webrtc/back_to_foreground_killed
[Android] BackToForeground when app is killed.
2 parents 749b014 + 2a31f3a commit bedfc23

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,15 @@ const options = {
386386
RNCallKeep.hasDefaultPhoneAccount(options);
387387
```
388388

389+
### backToForeground
390+
_This feature is available only on Android._
391+
392+
Use this to display the application in foreground if the application was in background state.
393+
This method will open the application if it was closed.
394+
395+
```js
396+
RNCallKeep.backToForeground();
397+
```
389398

390399
## Events
391400

android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import android.net.Uri;
3333
import android.os.Build;
3434
import android.os.Bundle;
35+
import android.view.WindowManager;
3536
import android.support.annotation.NonNull;
3637
import android.support.annotation.Nullable;
3738
import android.support.v4.app.ActivityCompat;
@@ -420,11 +421,22 @@ public void backToForeground() {
420421
Context context = getAppContext();
421422
String packageName = context.getApplicationContext().getPackageName();
422423
Intent focusIntent = context.getPackageManager().getLaunchIntentForPackage(packageName).cloneFilter();
424+
Activity activity = getCurrentActivity();
425+
boolean isOpened = activity != null;
426+
Log.d(TAG, "backToForeground, app isOpened ?" + (isOpened ? "true" : "false"));
423427

424-
focusIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
428+
if (isOpened) {
429+
focusIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
430+
activity.startActivity(focusIntent);
431+
} else {
425432

426-
Activity activity = getCurrentActivity();
427-
activity.startActivity(focusIntent);
433+
focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK +
434+
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED +
435+
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD +
436+
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
437+
438+
getReactApplicationContext().startActivity(focusIntent);
439+
}
428440
}
429441

430442
private void registerPhoneAccount(Context appContext) {

0 commit comments

Comments
 (0)