Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best way to debug it was to use the ADT (Android Developer Tools). There were a lot of small things wrong. This article was a very useful resource: <a href="http://devgirl.org/2013/09/17/how-to-write-a-phonegap-3-0-plugin-for-android/" rel="nofollow">http://devgirl.org/2013/09/17/how-to-write-a-phonegap-3-0-plugin-for-android/</a></p> <p>Here is the sms.java code:</p> <pre><code>package com.adamwadeharris.sms; import org.json.JSONArray; import org.json.JSONException; import android.app.PendingIntent; import android.content.Intent; import android.telephony.SmsManager; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; import org.apache.cordova.PluginResult; public class Sms extends CordovaPlugin { public final String ACTION_SEND_SMS = "send"; @Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals(ACTION_SEND_SMS)) { try { String phoneNumber = args.getString(0); String message = args.getString(1); String method = args.getString(2); if(method.equalsIgnoreCase("INTENT")){ invokeSMSIntent(phoneNumber, message); callbackContext.sendPluginResult(new PluginResult( PluginResult.Status.NO_RESULT)); } else{ send(phoneNumber, message); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); return true; } catch (JSONException ex) { callbackContext.sendPluginResult(new PluginResult( PluginResult.Status.JSON_EXCEPTION)); } } return false; } private void invokeSMSIntent(String phoneNumber, String message) { Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.putExtra("sms_body", message); sendIntent.putExtra("address", phoneNumber); sendIntent.setType("vnd.android-dir/mms-sms"); this.cordova.getActivity().startActivity(sendIntent); } private void send(String phoneNumber, String message) { SmsManager manager = SmsManager.getDefault(); PendingIntent sentIntent = PendingIntent.getActivity(this.cordova.getActivity(), 0, new Intent(), 0); manager.sendTextMessage(phoneNumber, null, message, sentIntent, null); } } </code></pre> <p>Here's the sms.js code:</p> <pre><code>var sms = { send: function(phone, message, method, successCallback, failureCallback) { cordova.exec( successCallback, failureCallback, 'Sms', 'send', [phone, message, method] ); } } module.exports = sms; </code></pre> <p>And here is the plugin.xml:</p> <pre><code>&lt;plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" id="com.adamwadeharris.sms" version="0.1.0"&gt; &lt;name&gt;Sms&lt;/name&gt; &lt;description&gt;Cordova SMS Send Plugin&lt;/description&gt; &lt;license&gt;MIT&lt;/license&gt; &lt;keywords&gt;cordova,phonegap,sms&lt;/keywords&gt; &lt;js-module src="www/sms.js" name="Sms"&gt; &lt;clobbers target="window.sms" /&gt; &lt;/js-module&gt; &lt;!-- android --&gt; &lt;platform name="android"&gt; &lt;config-file target="res/xml/config.xml" parent="/*"&gt; &lt;feature name="Sms"&gt; &lt;param name="android-package" value="com.adamwadeharris.sms.Sms"/&gt; &lt;/feature&gt; &lt;/config-file&gt; &lt;config-file target="AndroidManifest.xml" parent="/manifest"&gt; &lt;uses-permission android:name="android.permission.SEND_SMS" /&gt; &lt;/config-file&gt; &lt;source-file src="src/android/Sms.java" target-dir="src/com/adamwadeharris/sms" /&gt; &lt;/platform&gt; &lt;/plugin&gt; </code></pre> <p><strong>Edit</strong> Also, I have the plugin available on github: <a href="https://github.com/aharris88/phonegap-sms-plugin" rel="nofollow">https://github.com/aharris88/phonegap-sms-plugin</a></p> <p><strong>Edit</strong> This plugin has now moved to: <a href="https://github.com/cordova-sms/cordova-sms-plugin" rel="nofollow">https://github.com/cordova-sms/cordova-sms-plugin</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload