From a7e34a9eddf8355a88413a9ee1fae4d2e9792c18 Mon Sep 17 00:00:00 2001 From: Hassan Mojab Date: Wed, 23 Dec 2020 02:07:36 +0330 Subject: [PATCH] add autoSendMultiSim method --- .../src/main/java/com/react/SmsModule.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/react/SmsModule.java b/android/src/main/java/com/react/SmsModule.java index 7a27616..dfb3588 100644 --- a/android/src/main/java/com/react/SmsModule.java +++ b/android/src/main/java/com/react/SmsModule.java @@ -13,6 +13,7 @@ import com.facebook.react.bridge.WritableMap; import android.content.ContentValues; +import android.os.Build; import android.os.Bundle; import android.widget.Toast; import android.app.LoaderManager; @@ -30,11 +31,13 @@ import android.content.IntentFilter; import android.telephony.SmsManager; -import android.telephony.SmsMessage; +import android.telephony.SubscriptionInfo; +import android.telephony.SubscriptionManager; import java.util.HashMap; import java.util.Map; import java.util.ArrayList; +import java.util.List; import org.json.JSONArray; import org.json.JSONException; @@ -229,8 +232,8 @@ private void sendCallback(String message, boolean success) { @ReactMethod - public void autoSend(String phoneNumber, String message, final Callback errorCallback, - final Callback successCallback) { + public void autoSendMultiSim(Integer simSlot, String phoneNumber, String message, + final Callback errorCallback, final Callback successCallback) { cb_autoSend_succ = successCallback; cb_autoSend_err = errorCallback; @@ -284,6 +287,19 @@ public void onReceive(Context arg0, Intent arg1) { }, new IntentFilter(DELIVERED)); SmsManager sms = SmsManager.getDefault(); + + if (simSlot != null && simSlot < 2 && simSlot >= 0 + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { + SubscriptionManager localSubscriptionManager = SubscriptionManager.from(context); + if (localSubscriptionManager.getActiveSubscriptionInfoCount() > 1) { + List localList = localSubscriptionManager.getActiveSubscriptionInfoList(); + + SubscriptionInfo simInfo = (SubscriptionInfo) localList.get(simSlot); + + sms = SmsManager.getSmsManagerForSubscriptionId(simInfo.getSubscriptionId()); + } + } + ArrayList parts = sms.divideMessage(message); for (int i = 0; i < parts.size(); i++) { @@ -301,4 +317,10 @@ public void onReceive(Context arg0, Intent arg1) { sendCallback(e.getMessage(), false); } } + + @ReactMethod + public void autoSend(String phoneNumber, String message, final Callback errorCallback, + final Callback successCallback) { + autoSendMultiSim(null, phoneNumber, message, errorCallback, successCallback); + } }