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

add autoSendMultiSim method #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions android/src/main/java/com/react/SmsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> parts = sms.divideMessage(message);

for (int i = 0; i < parts.size(); i++) {
Expand All @@ -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);
}
}