Skip to content

Commit

Permalink
Merge pull request #32 from ferdil/master
Browse files Browse the repository at this point in the history
Android: use cordova.getThreadPool()
  • Loading branch information
dbaq committed May 7, 2015
2 parents 48d9630 + e28a714 commit 2ec01ff
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.cordova.plugins.sms"
version="0.1.2">
version="0.1.3">
<name>Cordova SMS Plugin</name>
<description>Cross-platform plugin for Cordova / PhoneGap to to easily send SMS. Available for Android and iOS.</description>
<license>MIT</license>
Expand Down
62 changes: 33 additions & 29 deletions src/android/Sms.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,38 @@ public class Sms extends CordovaPlugin {
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {

if (action.equals(ACTION_SEND_SMS)) {
try {
//parsing arguments
String phoneNumber = args.getJSONArray(0).join(";").replace("\"", "");
String message = args.getString(1);
String method = args.getString(2);
boolean replaceLineBreaks = Boolean.parseBoolean(args.getString(3));

// replacing \n by new line if the parameter replaceLineBreaks is set to true
if (replaceLineBreaks) {
message = message.replace("\\n", System.getProperty("line.separator"));
}

if (!checkSupport()) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "SMS not supported on this platform"));
return true;
}

if (method.equalsIgnoreCase("INTENT")) {
invokeSMSIntent(phoneNumber, message);
// always passes success back to the app
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
} else {
send(callbackContext, phoneNumber, message);
}
return true;
} catch (JSONException ex) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
}
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
try {
//parsing arguments
String phoneNumber = args.getJSONArray(0).join(";").replace("\"", "");
String message = args.getString(1);
String method = args.getString(2);
boolean replaceLineBreaks = Boolean.parseBoolean(args.getString(3));

// replacing \n by new line if the parameter replaceLineBreaks is set to true
if (replaceLineBreaks) {
message = message.replace("\\n", System.getProperty("line.separator"));
}
if (!checkSupport()) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "SMS not supported on this platform"));
return;
}
if (method.equalsIgnoreCase("INTENT")) {
invokeSMSIntent(phoneNumber, message);
// always passes success back to the app
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
} else {
send(callbackContext, phoneNumber, message);
}
return;
} catch (JSONException ex) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
}
}
});
return true;
}
return false;
}
Expand Down Expand Up @@ -139,4 +143,4 @@ public void onReceive(Context context, Intent intent) {
manager.sendTextMessage(phoneNumber, null, message, sentIntent, null);
}
}
}
}

0 comments on commit 2ec01ff

Please sign in to comment.