0

有人可以帮我解决这个问题:这是我的代码:

//js

var TestPlugin={ 
test:function(name,successCallback,failureCallback){
    console.log("navigator.service.sms smssend: ----------------");
    PhoneGap.exec(successCallback, failureCallback, "TestPlugin", "test", [name]);
}};

TestPlugin.test(
    "hubiao",
        function(){
            alert("success");
        },
        function(e){
            alert("fail");
            log(e);
        }
    );

//Android phonegap

public class TestPlugin extends Plugin {
@Override
public PluginResult execute(String action, JSONArray data, String callBackId) {

    if ("test".equalsIgnoreCase(action)) {  
        Log.d("DatePickerPluginListener execute", "test");  
        Context context=ctx.getContext();
        String name="";
        JSONObject fileInfo = new JSONObject();
        try {
            name = data.getString(0);
            fileInfo.put("hello", "Android"+name);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        final PluginResult r = new PluginResult(  
                Status.OK,fileInfo); 
        Log.i("TestPlugin", name);
        Toast.makeText(context,"User:"+name, Toast.LENGTH_LONG).show();
        return r;  
    }else{
         Log.d("DatePickerPlugin", "Invalid action : " + action + " passed"); 
         return new PluginResult(Status.INVALID_ACTION); 
    }
}

}

/// 重点:如果我添加:

 Toast.makeText(context,"User:"+name, Toast.LENGTH_LONG).show();

当我删除时,phonegap 会给出 failureCallback:

 Toast.makeText(context,"User:"+name, Toast.LENGTH_LONG).show();

phonegap 会给出successCallback。为什么?我不知道。有人可以帮助我吗?非常感谢!

4

1 回答 1

0

这不只是console.from的简单省略console.log()吗?

TestPlugin.test(
    "hubiao",
    function(){
        alert("success");
    },
    function(e){
        alert("fail");
        // log() is undefined.  console.log() is defined!
        console.log(e);
        // Or more likely you want the error message only
        console.log(e.message);
    }
);
于 2012-05-26T16:58:43.807 回答