Javascript 在phonegap android中未找到类异常
我正试图通过电子邮件和phonegap中的短信发送照片图像,因此编写了一个插件,作为java本机代码的桥梁。问题是当我从弹出的html“未找到类”警报中单击共享按钮时。即使在config.xml文件中正确声明了插件名称,我还是遇到了这个错误,请帮助我 这是它的java代码Javascript 在phonegap android中未找到类异常,javascript,android,plugins,cordova,Javascript,Android,Plugins,Cordova,我正试图通过电子邮件和phonegap中的短信发送照片图像,因此编写了一个插件,作为java本机代码的桥梁。问题是当我从弹出的html“未找到类”警报中单击共享按钮时。即使在config.xml文件中正确声明了插件名称,我还是遇到了这个错误,请帮助我 这是它的java代码 public class Share extends CordovaPlugin { private FileOutputStream outStream; private File file; Bitmap bm; pu
public class Share extends CordovaPlugin {
private FileOutputStream outStream;
private File file;
Bitmap bm;
public static final String ACTION_POSITION = "ShareImage";
Context context;
public Share(Context context) {
this.context = context;
}
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
throws JSONException {
if (ACTION_POSITION.equals(action)) {
try {
JSONObject arg_object = args.getJSONObject(0);
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.setType("image/jpg");
String uri = "@drawable/"+arg_object.getString("image")+".jpg";
int imageResource = context.getResources().getIdentifier(uri, null, context.getPackageName());
bm = BitmapFactory.decodeResource( context.getResources(), imageResource);
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
file = new File(extStorageDirectory+ "/Download/", "imageee.png");
try {
outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
System.out.println(" praise god........");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, arg_object.getString("image"));
this.cordova.getActivity().startActivity(sendIntent);
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
callbackContext.error(e.getMessage());
return false;
}
}
return true;
}
}
Share.js插件
var Share = function() {};
Share.prototype.show = function(success, fail, path) {
return cordova.exec( function(args) {
success(args);
}, function(args) {
fail(args);
}, 'Share','', 'ShareImage', [{"image": path}]);
};
if(!window.plugins) {
window.plugins = {};
}
if (!window.plugins.share) {
window.plugins.share = new Share();
}
config.xml文件中插件的声明
<plugins>
<plugin name="Share" value="com.picsswipe.Share"/>
</plugins>
html文件的onclick函数
instance.addEventHandler(PhotoSwipe.EventTypes.onToolbarTap, function(e){
if (e.toolbarAction === PhotoSwipe.Toolbar.ToolbarAction.none){
share();
}
});
function share() {
window.plugins.share.show({path: "Image"},
function(e) {
alert(e) }, // Success function
function() {
alert("Praise god :( ")
},// Failure function
imagename
);
}
请做那些更改。我把你所有的js代码都放在这里了
var Share = function() {};
Share.prototype.show = function(success, fail, path) {
return PhoneGap.exec(function(args) {success(args);}, function(args) {fail(args);}, 'Share', 'ShareImage', [{"image": path}]);
};
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin("share", new Share());
});
instance.addEventHandler(PhotoSwipe.EventTypes.onToolbarTap, function (e) {
if (e.toolbarAction === PhotoSwipe.Toolbar.ToolbarAction.none) {
share();
}
});
function share() {
var imagename = ""; // Please give your image name here or page from share() function
Share.prototype.show({path: "Image"},function (e) {alert(e);},function () {alert("Praise god :( ");},imagename);
}
config.xml
<feature name="Share">
<param name="android-package" value="$Share.java file package name$"/>
</feature>
使用哪个版本的phonegap,并给出包的代码、Share.java中的导入列表、html函数调用。为了便于我们找到问题答案,更新了我的问题,我正在使用cordova.2.9@power_ScriptorTanks来花时间回答我,我应用了上述方法,但它不起作用,我收到了这个错误“11-11 19:22:50.921:i/Web控制台(21576):无法运行构造函数:TypeError:对象#在上没有方法“addPlugin”file:///android_asset/www/js/cordova.js:317 “现在看看我更新了两次的代码。您是否在config.xml文件中更新了java包名称。我想知道您做了哪些更改,js代码的顺序和Share.java文件中的移除构造函数
<feature name="Share">
<param name="android-package" value="$Share.java file package name$"/>
</feature>
<feature name="Share">
<param name="android-package" value="org.apache.cordova.plugin.Share"/>
</feature>
public Share(Context context) {
this.context = context;
}