Android phonegap SMS插件中的操作错误无效

Android phonegap SMS插件中的操作错误无效,android,cordova,sms,phonegap-plugins,Android,Cordova,Sms,Phonegap Plugins,我正在为Android中的phonegap创建一个SMS插件。当我尝试发送消息时,收到一个无效的操作错误。我已经看过了。我的问题是相同的,但在链接中的任何答案都没有帮助 这是我的.js文件。 var SmsPlugin = function () {}; SmsPlugin.prototype.send = function (phone, message, successCallback, failureCallback) { return cordova.exec(suc

我正在为Android中的phonegap创建一个SMS插件。当我尝试发送消息时,收到一个无效的操作错误。我已经看过了。我的问题是相同的,但在链接中的任何答案都没有帮助

这是我的.js文件。

 var SmsPlugin = function () {};

SmsPlugin.prototype.send = function (phone, message, successCallback, failureCallback) {    
    return cordova.exec(successCallback, failureCallback, 'SmsPlugin', "SendSMS", [phone, message]);
};

window.sms = new SmsPlugin();
下面是我的.java文件

package com.*.PhonegapSMSDPN;

import org.apache.cordova.api.PluginResult;
import org.apache.cordova.api.PluginResult.Status;
import org.json.JSONArray;
import org.json.JSONException;

import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.Toast;

import org.apache.cordova.api.CordovaPlugin;

public class SmsPlugin extends CordovaPlugin {
    public final String ACTION_SEND_SMS = "SendSMS";

    public PluginResult execute(String action, JSONArray arg1, String callbackId) {
        Toast.makeText(this.cordova.getActivity(), action, Toast.LENGTH_SHORT).show();
        PluginResult result = new PluginResult(Status.INVALID_ACTION);
        Log.e("msg", action);
        if (action.equals(ACTION_SEND_SMS)) {
            try {
                String phoneNumber = arg1.getString(0);
                String message = arg1.getString(1);
                sendSMS(phoneNumber, message);
                result = new PluginResult(Status.OK);
            }
            catch (JSONException ex) {
                result = new PluginResult(Status.JSON_EXCEPTION, ex.getMessage());
                Log.e("error", result+" ");
            }           
        }

        return result;
    }

    private void sendSMS(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);
    }

}
我在config.xml文件中也做了必要的更改。 请指导我解决这个问题。谢谢


PS-i正在使用Phonegap2.7.0

您的js文件缺少一些代码。我也在phonegap中实现了一个sms插件,下面是我的js代码。您应该自定义插件路径

var SmsPlugin = function() {};

SmsPlugin.prototype.send = function(phone, message, successCallback, failureCallback) {
    return PhoneGap.exec(successCallback, failureCallback, 'SmsPlugin', "SendSMS", [phone, message]);
};

PhoneGap.addConstructor(function() {
    PhoneGap.addPlugin("sms", new SmsPlugin());
});

cordova.define("app/scripts/vendor/smsplugin", function (require, exports, module) {
    var exec = require('cordova/exec');
    var SmsPlugin = function () {};

    /**
     * Check if the device has a possibility to send and receive SMS
     */
    SmsPlugin.prototype.isSupported = function (successCallback, failureCallback) {
        return exec(successCallback, failureCallback, 'SmsPlugin', 'HasSMSPossibility', []);
    }
    /**
     * Send a message to the given phone number
     */
    SmsPlugin.prototype.send = function (phone, message, successCallback, failureCallback) {
        return exec(successCallback, failureCallback, 'SmsPlugin', 'SendSMS', [phone, message]);
    }

    var smsplugin = new SmsPlugin();
        module.exports = smsplugin;
});