1.编写安卓端代码
public class ElitetycPluginTest extends StandardFeature {
public void calcMyNameAddNum(IWebview pWebview, JSONArray array){
String CallBackID = array.optString(0);
String newstring = "我是原生代码返回::"+array.optString(1);
JSUtil.execCallback(pWebview,CallBackID,newstring, JSUtil.OK,false);
}
}

添加文件内容
在dcloud_properties.xml文件里面加上
<feature name="elitetyc" value="com.android.simple.ElitetycPluginTest"/>
2.编写前端代码调用方法
2-1编写插件文件plugin.js
! function(root, factory) {
if (typeof exports == 'object' && typeof module != 'undefined') {
module.exports = factory()
} else if (typeof define == 'function' && define.amd) {
define(factory)
} else {
document.addEventListener('plusready', function() {
var moduleName = 'elitetyc';
root.plus[moduleName] = factory()
}, false);
}
}(this, function() {
var _BARCODE = 'elitetyc';
var plugintest = {
CalcNameAddNumFunction: function(num, successCallback, errorCallback) {
var success = typeof successCallback !== 'function' ? null : function(args) {
successCallback(args);
},
fail = typeof errorCallback !== 'function' ? null : function(code) {
errorCallback(code);
};
var callbackID = plus.bridge.callbackId(success, fail);
return plus.bridge.exec(_BARCODE, "calcMyNameAddNum", [callbackID, num]);
}
};
return plugintest;
});

2-2前端页面引入plugin.js文件
var elitetyc = require('../../plugin.js');
在export default -data-return处加上
plugins: elitetyc

2-3编写点击事件
android() {
this.plugins.CalcNameAddNumFunction(
"这段文字是uniapp传过来的",
function(result) {
uni.showToast({
title: JSON.stringify(result),
icon: 'none',
duration: 5000
});
},
function(result) {
uni.showToast({
title: result,
icon: "none",
duration: 5000
});
}
);
},

4.将uniapp以本地打包的方式进行导出

选择生成本地app打包资源
打包后的文件夹 
导入到安卓工程里面

|