[英]cordova.exec error Class not found
我試圖編寫一個用於phonegap的插件,該插件將訪問我編寫的本機Java。 唯一的問題是,當我調用cordova.exec時,失敗回調消息是“找不到類”。 我假設這意味着它找不到Java文件,但我不知道為什么。
這是我的代碼。 使用Javascript:
var SerialHelper = {
getName: function(){
return "this is the name"
},
getSerial: function(success, failure) {
cordova.exec(
success, // success callback function
failure, // error callback function
'com.isabellaproducts.serialhelper.SerialHelper',
'getFableSerial',
[]
);
}
}
module.exports = SerialHelper;
Java的:
package com.isabellaproducs.serialhelper;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
import org.apache.cordova.*;
public class SerialHelper extends CordovaPlugin
{
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if ("getFableSerial".equals(action)) {
String serial = "15345344132354";
callbackContext.success(serial);
//callbackContext.sendPluginResult(new PluginResult(Status.OK, serial));
return true;
}
else{
callbackContext.error("method not found");
return false;
}
}
}
plugin.xml中
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="com.isabellaproducts.serialhelper"
version="1.0">
<name>SerialHelper</name>
<description>Serial Helper gets the Fable gives serial number access</description>
<license>MIT</license>
<keywords>serial, helper, fable</keywords>
<js-module src="www/serial_helper.js" name="SerialHelper">
<clobbers target="com.isabellaproducts.serialhelper" />
</js-module>
<!-- android -->
<platform name="android">
<source-file src="src/android/com/isabellaproducts/serialhelper/SerialHelper.java" target-dir="src/com/isabellaproducts/serialhelper" />
<config-file target="res/xml/config.xml" parent="/*">
<feature name="SerialHelper">
<param name="android-package" value="com.isabellaproducts.serialhelper.SerialHelper"/>
</feature>
</config-file>
</platform>
</plugin>
在logcat中,出現此錯誤:
D/PluginManager(12316): exec() call to unknown plugin: SerialHelper
任何幫助將非常感激。
謝謝。
哇...。所以,我將插件放在自定義包中。 那簡直糟透了!
簡單的更改:從com.isabellaproducts.serialhelper到com.phonegap.plugins.serialhlper
現在看起來像這樣。 使用Javascript:
var SerialHelper = {
getName: function(){
return "this is the name"
},
getSerial: function(success, failure) {
cordova.exec(
success, // success callback function
failure, // error callback function
'SerialHelper',
'getFableSerial',
[]
);
}
}
module.exports = SerialHelper;
Java的:
package com.phonegap.plugins.serialhelper;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
import org.apache.cordova.*;
public class SerialHelper extends CordovaPlugin
{
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if ("getFableSerial".equals(action)) {
String serial = "15345344132354";
callbackContext.success(serial);
//callbackContext.sendPluginResult(new PluginResult(Status.OK, serial));
return true;
}
else{
callbackContext.error("method not found");
return false;
}
}
}
plugin.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="com.phonegap.plugins.serialhelper"
version="1.0">
<name>SerialHelper</name>
<description>Serial Helper gets the Fable gives serial number access</description>
<license>MIT</license>
<keywords>serial, helper, fable</keywords>
<js-module src="www/serial_helper.js" name="SerialHelper">
<clobbers target="com.phonegap.plugins.serialhelper" />
</js-module>
<!-- android -->
<platform name="android">
<source-file src="src/android/com/phonegap/plugins/serialhelper/SerialHelper.java" target-dir="src/com/phonegap/plugins/serialhelper" />
<config-file target="res/xml/config.xml" parent="/*">
<feature name="SerialHelper">
<param name="android-package" value="com.phonegap.plugins.serialhelper.SerialHelper"/>
</feature>
</config-file>
</platform>
</plugin>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.