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フォンギャップ

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 に答える