用到的jar包 ( 1.android_plugin_framework_v0.3.jar,2.android_plugin_demo_description.jar)
jar包2是里面只有一个描述类,可自定义
主程序开发:导入两个jar包
1.在清单文件 加上(sharedUserID 为宿主的标记 标记要一致)
android:sharedUserId="xxx.xxx.xxx"2.查找插件:
PluginSearch psearch = new PluginSearch(); List<Plugin> plugins = psearch.getPlugins(this);
3.将插件再组装一下:
PluginBuilder pbuilder = new PluginBuilder(this); plugins = pbuilder.buildPluginsDescrition(plugins);
4.遍历插件获取描述:
//MainDescript继承于jar的描述类 MainDescript des = pdes.getDescription(this, plug); des.getSubTitle();//描述类的方法 des.getDescription(); des.getDescription();5.调用插件的方法:
List<PluginFeature> features = plug.getFeatures(); for (final PluginFeature pf : features) { for (final PluginFeatureMethod fm : pf.getMethods()) { // 添加插件,并且设置执行事件 item.addPluginMethod(fm, new View.OnClickListener() { @Override public void onClick(View v) { PluginInvoke pi = new PluginInvoke(MainActivity.this); try { pi.invoke(plug, pf, fm); } catch (Exception e) { e.printStackTrace(); } } }); } }6.调用插件的 Intent
// 遍历intent Map<String, PluginIntent> intents = plug.getIntents(); Iterator<Map.Entry<String, PluginIntent>> iterator = intents.entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry<String, PluginIntent> entry = iterator.next();btn.setText(entry.getValue()); btn.setOnClickListener(new View.OnClickListener() {}@Override public void onClick(View v) { PluginInvoke pi = new PluginInvoke(MainActivity.this); pi.invoke(entry.getValue()); }});
插件开发:导入jar包2
1.在清单文件 加上(sharedUserID 为宿主的标记 标记要一致)
android:sharedUserId="xxx.xxx.xxx"
2.在assets目录下创建 plugin.xml文件
<?xml version="1.0" encoding="UTF-8"?> <!-- 插件提供的功能(类) --> <plugin-features> <!-- 描述类,这个是自定义的 --> <description name="com.s5.test.Function"/> <intent action="com.s5.test.MainActivity" key="main">启动</intent> <!-- 这是一个功能(类) --> <feature name="com.s5.test.MainActivity"> <!-- 方法列表 --> <!-- name 方法名 MainActivity里提供的方法callPhone()--> <method need-context="true" name="callPhone" >给10086打电话</method> <method need-context="true" name="callWeb" >打开作者博客</method> </feature> </plugin-features>3.feature 里写方法提供使用
附个demo
链接: http://pan.baidu.com/s/1mimx4xU 密码: ynny