Skip to content

Commit

Permalink
[native] Fix RECEIVER_EXPORTED/RECEIVER_NOT_EXPORTED Android build issue
Browse files Browse the repository at this point in the history
Summary: Got this fix from [this StackOverflow post](https://stackoverflow.com/q/77371855/427010).

Test Plan: Confirmed that the crash-on-start for Android dev builds no longer occurs with this patch

Reviewers: varun, will

Reviewed By: will

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D13457
  • Loading branch information
Ashoat committed Sep 25, 2024
1 parent d05b489 commit 0fb37af
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package app.comm.android;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.database.CursorWindow;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.multidex.MultiDexApplication;
import app.comm.android.commservices.CommServicesPackage;
Expand All @@ -23,6 +27,8 @@
import java.lang.reflect.InvocationTargetException;
import java.security.Security;
import java.util.List;
import org.jetbrains.annotations.Nullable;

public class MainApplication
extends MultiDexApplication implements ReactApplication {

Expand Down Expand Up @@ -75,6 +81,18 @@ public ReactNativeHost getReactNativeHost() {
}
}

@Override
public Intent
registerReceiver(@Nullable BroadcastReceiver receiver, IntentFilter filter) {
if (Build.VERSION.SDK_INT >= 34 &&
getApplicationInfo().targetSdkVersion >= 34) {
return super.registerReceiver(
receiver, filter, Context.RECEIVER_EXPORTED);
} else {
return super.registerReceiver(receiver, filter);
}
}

@Override
public void onCreate() {
super.onCreate();
Expand Down

0 comments on commit 0fb37af

Please sign in to comment.