您好我开发了一个电话间隙插件来查看目录是否为空。
我使用下面的代码
public PluginResult execute(String arg0, final JSONArray arg1, String arg2) {
if ( arg0.equals(SHOW6) )
{
PluginResult result = null;
File file = new File("/mnt/sdcard/koinoxrista/todesktop/");
if(file.isDirectory()){
if(file.list().length>0){
/* Builder dialog = new AlertDialog.Builder(ctx);
dialog.setNegativeButton("Ok", null);
AlertDialog alert = dialog.create();
alert.setTitle("Failure");
alert.setMessage("Directory is not empty!");
alert.show();
*/
return new PluginResult(Status.ERROR, "Directory is not empty!");
// System.out.println("Directory is not empty!");
}else{
/*
Builder dialog = new AlertDialog.Builder(ctx);
dialog.setNegativeButton("Ok", null);
AlertDialog alert = dialog.create();
alert.setTitle("Failure");
alert.setMessage("Directory is empty!");
alert.show();
*/
return new PluginResult(Status.OK, "Directory is empty!");
// System.out.println("Directory is empty!");
}
}else{
// System.out.println("This is not a directory");
}
}
这就是我从 js 中调用它的方式
var msgbox = function() {
};
msgbox.prototype.show6 = function(success, fail) {
return PhoneGap.exec(success, fail, "msgbox", "show6", []);
};
function success(e){globalcreate = 0; alert(e);}
function fail(r){globalcreate = 1; alert(r);}
msgbox = new msgbox();
我想提醒目录是否为空。
如何设置回调?
如果我在我的 .java 中取消注释警报对话框,我会收到正确的结果。