Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-native 0.73 compatibility #7

Open
Akatroj opened this issue Feb 20, 2024 · 1 comment
Open

react-native 0.73 compatibility #7

Akatroj opened this issue Feb 20, 2024 · 1 comment

Comments

@Akatroj
Copy link

Akatroj commented Feb 20, 2024

Hello, while I don't use this library in our project (we are using react-native-sms-retriever instead), I noticed that this is basically a fork of that library, and the issue probably applies to this library as well.

When I was upgrading our project to react-native 0.73, I noticed that the sms retriever was not working, and with some debugging I found the reason: https://stackoverflow.com/a/77276774/17101184

Based on this answer, I made a patch for the original library. As I cannot publish it in that repo anymore (it was archived and is read-only now), I'm posting it here in the hopes that somebody using either of these libraries find this and it saves them some time:

diff --git a/node_modules/react-native-sms-retriever/android/src/main/java/me/furtado/smsretriever/SmsHelper.java b/node_modules/react-native-sms-retriever/android/src/main/java/me/furtado/smsretriever/SmsHelper.java
index b1ab5f4..5495d66 100644
--- a/node_modules/react-native-sms-retriever/android/src/main/java/me/furtado/smsretriever/SmsHelper.java
+++ b/node_modules/react-native-sms-retriever/android/src/main/java/me/furtado/smsretriever/SmsHelper.java
@@ -1,7 +1,11 @@
 package me.furtado.smsretriever;
 
+import static android.content.Context.RECEIVER_EXPORTED;
+
 import android.content.BroadcastReceiver;
 import android.content.IntentFilter;
+import android.os.Build;
+
 import androidx.annotation.NonNull;
 
 import com.facebook.react.bridge.Promise;
@@ -57,7 +61,11 @@ final class SmsHelper {
         final IntentFilter intentFilter = new IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION);
 
         try {
-            mContext.registerReceiver(mReceiver, intentFilter);
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+                mContext.registerReceiver(mReceiver, intentFilter, RECEIVER_EXPORTED);
+            } else {
+                mContext.registerReceiver(mReceiver, intentFilter);
+            }
             return true;
         } catch (Exception e) {
             e.printStackTrace();
@Akatroj
Copy link
Author

Akatroj commented Feb 20, 2024

this is specifically because react-native 0.73 bumped the targetSdkVersion to 34, which started throwing an exception when registering the receiver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant