Skip to content
Open
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ version: 2.1
# Default VM config to be used for macOS builds
macos_config: &macos_config
macos:
xcode: 16.0.0
resource_class: macos.m1.large.gen1
xcode: 16.4.0
resource_class: m4pro.medium
Comment on lines +6 to +7
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change this because of this error on CI: "Job was rejected because resource class macos.m1.large.gen1, image xcode:16.0.0 is not a valid resource class"

shell: /bin/bash --login -eo pipefail

setup_env_file: &setup_env_file
Expand Down
36 changes: 33 additions & 3 deletions android/src/newarch/IntercomModule.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.intercom.reactnative;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.Application;
import android.content.Intent;
import android.util.Log;
Expand Down Expand Up @@ -90,17 +91,46 @@ public static void handleRemotePushWithCustomStack(@NonNull Application applicat
public static void handleRemotePushMessage(@NonNull Application application, RemoteMessage remoteMessage) {
try {
TaskStackBuilder customStack = TaskStackBuilder.create(application);
Intent launchIntent = application.getPackageManager().getLaunchIntentForPackage(application.getPackageName());
if (launchIntent != null) {
customStack.addNextIntent(launchIntent);

if (!isAppInForeground(application)) {
Intent launchIntent = application.getPackageManager().getLaunchIntentForPackage(application.getPackageName());
if (launchIntent != null) {
customStack.addNextIntent(launchIntent);
}
}

handleRemotePushWithCustomStack(application, remoteMessage, customStack);
} catch (Exception err) {
Log.e(NAME, "handleRemotePushMessage error:");
Log.e(NAME, err.toString());
}
}

private static boolean isAppInForeground(@NonNull Application application) {
try {
ActivityManager activityManager = (ActivityManager) application.getSystemService(android.content.Context.ACTIVITY_SERVICE);
if (activityManager == null) {
return false;
}
java.util.List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
if (appProcesses == null) {
return false;
}
String packageName = application.getPackageName();
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
&& appProcess.processName.equals(packageName)) {
return true;
}
}
return false;
} catch (Exception err) {
Log.e(NAME, "isAppInForeground error:");
Log.e(NAME, err.toString());
return false;
}
}

public static void sendTokenToIntercom(Application application, @NonNull String token) {
if (application == null || token == null || token.isEmpty()) {
Log.w(NAME, "sendTokenToIntercom: application or token is null or empty");
Expand Down
36 changes: 33 additions & 3 deletions android/src/oldarch/IntercomModule.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.intercom.reactnative;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.Application;
import android.content.Intent;
import android.util.Log;
Expand Down Expand Up @@ -82,17 +83,46 @@ public static void handleRemotePushWithCustomStack(@NonNull Application applicat
public static void handleRemotePushMessage(@NonNull Application application, RemoteMessage remoteMessage) {
try {
TaskStackBuilder customStack = TaskStackBuilder.create(application);
Intent launchIntent = application.getPackageManager().getLaunchIntentForPackage(application.getPackageName());
if (launchIntent != null) {
customStack.addNextIntent(launchIntent);

if (!isAppInForeground(application)) {
Intent launchIntent = application.getPackageManager().getLaunchIntentForPackage(application.getPackageName());
if (launchIntent != null) {
customStack.addNextIntent(launchIntent);
}
}

handleRemotePushWithCustomStack(application, remoteMessage, customStack);
} catch (Exception err) {
Log.e(NAME, "handleRemotePushMessage error:");
Log.e(NAME, err.toString());
}
}

private static boolean isAppInForeground(@NonNull Application application) {
try {
ActivityManager activityManager = (ActivityManager) application.getSystemService(android.content.Context.ACTIVITY_SERVICE);
if (activityManager == null) {
return false;
}
java.util.List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
if (appProcesses == null) {
return false;
}
String packageName = application.getPackageName();
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
&& appProcess.processName.equals(packageName)) {
return true;
}
}
return false;
} catch (Exception err) {
Log.e(NAME, "isAppInForeground error:");
Log.e(NAME, err.toString());
return false;
}
}

public static void sendTokenToIntercom(Application application, @NonNull String token) {
intercomPushClient.sendTokenToIntercom(application, token);
Log.d(NAME, "sendTokenToIntercom");
Expand Down