arpansharma7474/rn-sms-retriever

react-native 0.73 compatibility

Opened this issue · 1 comments

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();

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