Skip to content

Commit 6762b55

Browse files
authored
Revert "Fix Android deep link push notifications causing app restart in foreg…" (#375)
This reverts commit 524a2fd.
1 parent 4ea9993 commit 6762b55

File tree

2 files changed

+6
-66
lines changed

2 files changed

+6
-66
lines changed

android/src/newarch/IntercomModule.java

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.intercom.reactnative;
22

33
import android.app.Activity;
4-
import android.app.ActivityManager;
54
import android.app.Application;
65
import android.content.Intent;
76
import android.util.Log;
@@ -91,46 +90,17 @@ public static void handleRemotePushWithCustomStack(@NonNull Application applicat
9190
public static void handleRemotePushMessage(@NonNull Application application, RemoteMessage remoteMessage) {
9291
try {
9392
TaskStackBuilder customStack = TaskStackBuilder.create(application);
94-
95-
if (!isAppInForeground(application)) {
96-
Intent launchIntent = application.getPackageManager().getLaunchIntentForPackage(application.getPackageName());
97-
if (launchIntent != null) {
98-
customStack.addNextIntent(launchIntent);
99-
}
93+
Intent launchIntent = application.getPackageManager().getLaunchIntentForPackage(application.getPackageName());
94+
if (launchIntent != null) {
95+
customStack.addNextIntent(launchIntent);
10096
}
101-
10297
handleRemotePushWithCustomStack(application, remoteMessage, customStack);
10398
} catch (Exception err) {
10499
Log.e(NAME, "handleRemotePushMessage error:");
105100
Log.e(NAME, err.toString());
106101
}
107102
}
108103

109-
private static boolean isAppInForeground(@NonNull Application application) {
110-
try {
111-
ActivityManager activityManager = (ActivityManager) application.getSystemService(android.content.Context.ACTIVITY_SERVICE);
112-
if (activityManager == null) {
113-
return false;
114-
}
115-
java.util.List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
116-
if (appProcesses == null) {
117-
return false;
118-
}
119-
String packageName = application.getPackageName();
120-
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
121-
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
122-
&& appProcess.processName.equals(packageName)) {
123-
return true;
124-
}
125-
}
126-
return false;
127-
} catch (Exception err) {
128-
Log.e(NAME, "isAppInForeground error:");
129-
Log.e(NAME, err.toString());
130-
return false;
131-
}
132-
}
133-
134104
public static void sendTokenToIntercom(Application application, @NonNull String token) {
135105
if (application == null || token == null || token.isEmpty()) {
136106
Log.w(NAME, "sendTokenToIntercom: application or token is null or empty");

android/src/oldarch/IntercomModule.java

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.intercom.reactnative;
22

33
import android.app.Activity;
4-
import android.app.ActivityManager;
54
import android.app.Application;
65
import android.content.Intent;
76
import android.util.Log;
@@ -83,46 +82,17 @@ public static void handleRemotePushWithCustomStack(@NonNull Application applicat
8382
public static void handleRemotePushMessage(@NonNull Application application, RemoteMessage remoteMessage) {
8483
try {
8584
TaskStackBuilder customStack = TaskStackBuilder.create(application);
86-
87-
if (!isAppInForeground(application)) {
88-
Intent launchIntent = application.getPackageManager().getLaunchIntentForPackage(application.getPackageName());
89-
if (launchIntent != null) {
90-
customStack.addNextIntent(launchIntent);
91-
}
85+
Intent launchIntent = application.getPackageManager().getLaunchIntentForPackage(application.getPackageName());
86+
if (launchIntent != null) {
87+
customStack.addNextIntent(launchIntent);
9288
}
93-
9489
handleRemotePushWithCustomStack(application, remoteMessage, customStack);
9590
} catch (Exception err) {
9691
Log.e(NAME, "handleRemotePushMessage error:");
9792
Log.e(NAME, err.toString());
9893
}
9994
}
10095

101-
private static boolean isAppInForeground(@NonNull Application application) {
102-
try {
103-
ActivityManager activityManager = (ActivityManager) application.getSystemService(android.content.Context.ACTIVITY_SERVICE);
104-
if (activityManager == null) {
105-
return false;
106-
}
107-
java.util.List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
108-
if (appProcesses == null) {
109-
return false;
110-
}
111-
String packageName = application.getPackageName();
112-
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
113-
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
114-
&& appProcess.processName.equals(packageName)) {
115-
return true;
116-
}
117-
}
118-
return false;
119-
} catch (Exception err) {
120-
Log.e(NAME, "isAppInForeground error:");
121-
Log.e(NAME, err.toString());
122-
return false;
123-
}
124-
}
125-
12696
public static void sendTokenToIntercom(Application application, @NonNull String token) {
12797
intercomPushClient.sendTokenToIntercom(application, token);
12898
Log.d(NAME, "sendTokenToIntercom");

0 commit comments

Comments
 (0)