trytest
trytest
  • 发布:2015-10-31 11:08
  • 更新:2015-11-10 18:02
  • 阅读:1907

能给个自定义android的插件并集成到移动项目中的demo吗(自定义插件,一个加法函数就行)?

分类:5+ SDK

按照 android插件的开发文档做的,始终都提示插件模块没加载(在HBuilder中创建的移动项目,并使用android的模拟器调试)。如果方便的话,麻烦指点下。

2015-10-31 11:08 负责人:无 分享
已邀请:
磊子

磊子

上面就是我开发成功后总结的步骤,按照上面的步骤做就可以成功。如果还不行,我再给你整理个例子。

  • dreamlwj

    求一个例子,我不太清楚在eclipse里面把插件写好后,怎么打包?然后放到hbuilder的什么目录下,然后怎么做关联,然后怎么调用?

    2015-12-22 13:30

磊子

磊子

1、书写插件开发类,类继承自StandardFeature,插件的初始化方法:public void init(AbsMgr arg0, String arg1);释放方法:public void dispose(String arg0);
插件中异步调用方法:
public void PluginTestFunctionArrayArgu(IWebview pWebview, JSONArray array)
{
String ReturnString = null;
String CallBackID = array.optString(0);
JSONArray newArray = null;
try {

        newArray = new JSONArray(array.optString(1));            
        String inValue1 = newArray.getString(0);  
        String inValue2 = newArray.getString(1);  
        String inValue3 = newArray.getString(2);  
        String inValue4 = newArray.getString(3);  
        ReturnString = inValue1 + "-" + inValue2 + "-" + inValue3 + "-" + inValue4;  
    } catch (JSONException e) {  
        // TODO Auto-generated catch block  
        e.printStackTrace();  
    }  

    JSUtil.execCallback(pWebview, CallBackID, ReturnString, JSUtil.OK, false);  
}  

插件同步调用方法:
public String testMethodSync(IWebview pWebview, JSONArray array)
{
JSONArray newArray = null;
JSONObject retJSONObj = null;
try {

        newArray = array.optJSONArray(0);  
        String inValue1 = newArray.getString(0);  
        String inValue2 = newArray.getString(1);  
        String inValue3 = newArray.getString(2);  

        retJSONObj = new JSONObject();  
        retJSONObj.putOpt("RetArgu1", inValue1);  
        retJSONObj.putOpt("RetArgu2", inValue2);  
        retJSONObj.putOpt("RetArgu3", inValue3);  

    } catch (JSONException e1) {  
        // TODO Auto-generated catch block  
        e1.printStackTrace();  
    }         

    return JSUtil.wrapJsVar(retJSONObj);  
}  

2、在assets/data/properties.xml中注册插件,实例代码如下:
<feature
name="plugintest" //插件名称
value="com.itlamp.android.plugin.PluginTest" > //插件实现类
</feature>

3、在assets/apps/XXXX/www/manifest.json中增加插件的使用权限,在文件的"permissions"的最下面增加如下代码:

"plugintest": {
"description": "测试控件"
}
4、在前段html页面中用JavaScript注册控件并进行调用,事例代码如下:
<script type="text/javascript">
document.addEventListener( "plusready", function()
{
var _BARCODE = 'plugintest'/插件的别名/,B = window.plus.bridge/插件调用桥梁/;
var plugintest =
{
//异步方法实现
testMethod : function (Argus1, Argus2, Argus3, successCallback, errorCallback )
{
var success = typeof successCallback !== 'function' ? null : function(args)
{
successCallback(args);
},
fail = typeof errorCallback !== 'function' ? null : function(code)
{
errorCallback(code);
};
callbackID = B.callbackId(success, fail);

                    return B.exec(_BARCODE, "testMethod", [callbackID, Argus1, Argus2, Argus3]);  
                },  
                //同步方法实现  
                testMethodSync : function(Argus){  
                    return B.execSync(_BARCODE, "testMethodSync", [Argus]);  
                }  
            };  
            window.plus.plugintest = plugintest;  
        }, true );  

        //调用例子  
        function testMethod() {               
              plus.plugintest.testMethod("张三","男","25岁", function( result ) {alert( result[0]  + "_" + result[1]  + "_" + result[2]);},function(result){alert(result)});  
                }  

                function testMethodSync() {  
                    var retval=plus.plugintest.testMethodSync(["李四","男","28岁"]);  
                    alert(retval.RetArgu1+"-"+retval.RetArgu2+"-"+retval.RetArgu3);  
                }          

</script>

该问题目前已经被锁定, 无法添加新回复