Skip to content

Commit

Permalink
Merge pull request #44 from v-kryuchkov/main
Browse files Browse the repository at this point in the history
Fix crash on API 33
  • Loading branch information
mrshakirov authored Nov 19, 2024
2 parents 78dab31 + 7175b08 commit a4bc85a
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void subscribe() throws RNSmsUserConsentException {
SmsRetriever.getClient(getCurrentActivity()).startSmsUserConsent(null);

broadcastReceiver = new SmsBroadcastReceiver(getCurrentActivity(), this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
getCurrentActivity().registerReceiver(
broadcastReceiver,
new IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION),
Expand Down Expand Up @@ -86,10 +86,18 @@ private void unsubscribe() throws RNSmsUserConsentException {
);
}

activity.unregisterReceiver(broadcastReceiver);
broadcastReceiver = null;
try {
activity.unregisterReceiver(broadcastReceiver);
broadcastReceiver = null;

reactContext.removeActivityEventListener(listener);
reactContext.removeActivityEventListener(listener);
} catch (IllegalArgumentException e) {
// There is a small chance that the receiver's onReceive(Context, Intent) method is called more than once, since it is registered with multiple IntentFilters, creating the potential for an IllegalArgumentException being thrown from Context#unregisterReceiver(BroadcastReceiver).
throw new RNSmsUserConsentException(
Errors.NULL_BROADCAST_RECEIVER,
"Could not unsubscribe, broadcastReceiver is null"
);
}
}

private void resubscribe() {
Expand Down

0 comments on commit a4bc85a

Please sign in to comment.