下面是我的代碼,但它不工作時,誤差函數調用僅如何調用本地警告框,同時使用PhoneGap的
本地插件
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
請幫助解決這個
感謝,但實際需要的插件 – Rick 2013-02-15 18:36:49
是用Java編寫或JavaScript您的插件代碼? – PavanBhushan 2013-02-16 11:52:33
謝謝,我的代碼是用Java編寫的 – Rick 2013-02-18 07:59:45