下面是我的代码,但它不起作用,错误函数只调用
原生插件
package com.gami.fre;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.widget.Toast;
public class ConfirmBox extends Plugin {
public static final String NATIVE_ACTION_STRING="nativeAction";
public static final String SUCCESS_PARAMETER="success";
public Context context;
public int result=0;
@Override
public PluginResult execute(String action, JSONArray data, String callbackId)
{
Log.d("HelloPlugin", "PhoneGap/Cordova!");
//only perform the action if it is the one that should be invoked
if (NATIVE_ACTION_STRING.equals(action))
{
String resultType = null;
try {
resultType = data.getString(0);
}
catch (Exception ex) {
Log.d("HelloPlugin", ex.toString());
}
if (resultType.equals(SUCCESS_PARAMETER))
{
Log.d("hisu", resultType);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
//alertDialogBuilder.setTitle("Your Title");
// set dialog message
alertDialogBuilder
.setMessage("Are you sure want to Exit!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,int id)
{
//ConfirmBox.this.finish();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,int id)
{
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
return new PluginResult(PluginResult.Status.OK, result);
}
else
{
return new PluginResult(PluginResult.Status.ERROR, "Oops, Error :(");
}
}
return null;
}
}
电话间隙通话
<script type="text/javascript" >
function callNativePlugin( returnSuccess )
{
Helo.callNativeFunction( nativePluginResultHandler, nativePluginErrorHandler, returnSuccess );
}
function nativePluginResultHandler (result)
{
//alert("SUCCESS: \r\n"+result );
}
function nativePluginErrorHandler (error)
{
alert("ERROR: \r\n"+error );
}
每次只调用错误函数;成功调用正在发生,但在第一行之后立即跳过。即在日志打印后从函数中跳过并显示错误:NULL
请帮助解决这个问题