|
8 | 8 |
|
9 | 9 | import androidx.annotation.NonNull; |
10 | 10 | import androidx.annotation.Nullable; |
| 11 | +import androidx.lifecycle.Lifecycle; |
| 12 | +import androidx.lifecycle.ProcessLifecycleOwner; |
11 | 13 |
|
12 | 14 | import com.facebook.react.bridge.Promise; |
13 | 15 | import com.facebook.react.bridge.ReactApplicationContext; |
@@ -82,17 +84,34 @@ public static void handleRemotePushWithCustomStack(@NonNull Application applicat |
82 | 84 | public static void handleRemotePushMessage(@NonNull Application application, RemoteMessage remoteMessage) { |
83 | 85 | try { |
84 | 86 | TaskStackBuilder customStack = TaskStackBuilder.create(application); |
85 | | - Intent launchIntent = application.getPackageManager().getLaunchIntentForPackage(application.getPackageName()); |
86 | | - if (launchIntent != null) { |
87 | | - customStack.addNextIntent(launchIntent); |
| 87 | + |
| 88 | + if (!isAppInForeground(application)) { |
| 89 | + Intent launchIntent = application.getPackageManager().getLaunchIntentForPackage(application.getPackageName()); |
| 90 | + if (launchIntent != null) { |
| 91 | + customStack.addNextIntent(launchIntent); |
| 92 | + } |
88 | 93 | } |
| 94 | + |
89 | 95 | handleRemotePushWithCustomStack(application, remoteMessage, customStack); |
90 | 96 | } catch (Exception err) { |
91 | 97 | Log.e(NAME, "handleRemotePushMessage error:"); |
92 | 98 | Log.e(NAME, err.toString()); |
93 | 99 | } |
94 | 100 | } |
95 | 101 |
|
| 102 | + private static boolean isAppInForeground(@NonNull Application application) { |
| 103 | + try { |
| 104 | + return ProcessLifecycleOwner.get() |
| 105 | + .getLifecycle() |
| 106 | + .getCurrentState() |
| 107 | + .isAtLeast(Lifecycle.State.STARTED); |
| 108 | + } catch (Exception err) { |
| 109 | + Log.e(NAME, "isAppInForeground error:"); |
| 110 | + Log.e(NAME, err.toString()); |
| 111 | + return false; |
| 112 | + } |
| 113 | + } |
| 114 | + |
96 | 115 | public static void sendTokenToIntercom(Application application, @NonNull String token) { |
97 | 116 | intercomPushClient.sendTokenToIntercom(application, token); |
98 | 117 | Log.d(NAME, "sendTokenToIntercom"); |
|
0 commit comments