Skip to content

Commit

Permalink
Merge pull request #37 from kentmw/master
Browse files Browse the repository at this point in the history
#14 - Adding ability to create intent with multiple recipients
  • Loading branch information
dbaq committed Jun 15, 2015
2 parents 86dd9fb + 7ea993c commit 79802e4
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/android/Sms.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public boolean execute(String action, final JSONArray args, final CallbackContex
public void run() {
try {
//parsing arguments
String phoneNumber = args.getJSONArray(0).join(";").replace("\"", "");
String separator = ";";
if (android.os.Build.MANUFACTURER.equalsIgnoreCase("Samsung")) {
// See http://stackoverflow.com/questions/18974898/send-sms-through-intent-to-multiple-phone-numbers/18975676#18975676
separator = ",";
}
String phoneNumber = args.getJSONArray(0).join(separator).replace("\"", "");
String message = args.getString(1);
String method = args.getString(2);
boolean replaceLineBreaks = Boolean.parseBoolean(args.getString(3));
Expand All @@ -46,7 +51,7 @@ public void run() {
return;
}
if (method.equalsIgnoreCase("INTENT")) {
invokeSMSIntent(phoneNumber, message);
invokeSMSIntent(phoneNumber, message);
// always passes success back to the app
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
} else {
Expand Down Expand Up @@ -83,8 +88,10 @@ private void invokeSMSIntent(String phoneNumber, String message) {
}
} else {
sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("smsto:" + Uri.encode(phoneNumber)));
sendIntent.putExtra("sms_body", message);
// See http://stackoverflow.com/questions/7242190/sending-sms-using-intent-does-not-add-recipients-on-some-devices
sendIntent.putExtra("address", phoneNumber);
sendIntent.setData(Uri.parse("smsto:" + Uri.encode(phoneNumber)));
}
this.cordova.getActivity().startActivity(sendIntent);
}
Expand All @@ -93,9 +100,9 @@ private void send(final CallbackContext callbackContext, String phoneNumber, Str
SmsManager manager = SmsManager.getDefault();
final ArrayList<String> parts = manager.divideMessage(message);

// by creating this broadcast receiver we can check whether or not the SMS was sent
// by creating this broadcast receiver we can check whether or not the SMS was sent
final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

boolean anyError = false; //use to detect if one of the parts failed
int partsCount = parts.size(); //number of parts to send

Expand Down

0 comments on commit 79802e4

Please sign in to comment.