plugin.xml文件除了定义插件属性外,开发者也可以根据自己需求添加自定义的属性。
demo源码下载地址 http://git.oschina.net/plug/apkplugBundles/tree/master/PluginDemo
1.配置代码如下
<?xml version="1.0" encoding="UTF-8"?> <plugin-features Bundle-Name="plugin文件传参" Bundle-SymbolicName="com.apkplug.plugindemo" Bundle-Version="1.0.3" date="2012.11.28" Install="false" provider-name="插件开发商的名称" provider-url="" Bundle-Activator="com.apkplug.plugindemo.SimpleBundle" Bundle-Activity="com.apkplug.plugindemo.MainActivity" mykey="我是插件自定义的一个参数" > </plugin-features>
2.定义com.apkplug.plugindemo.BundleContextFactory 用来保存插件启动时的上下文BundleContext
3.编写 com.apkplug.plugindemo.SimpleBundle implements BundleActivator
public class SimpleBundle implements BundleActivator { public void start(BundleContext context) throws Exception { System.out.println("Simple Bundle " + context.getBundle().getBundleId() + " has started."); //保存插件上下文BundleContext 在Activity中使用 BundleContextFactory.getInstance().setBundleContext(context); } public void stop(BundleContext context) { System.out.println("Simple Bundle " + context.getBundle().getBundleId() + " has stopped."); } }
4.在com.apkplug.plugindemo.MainActivity中获取mykey
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView info=(TextView) this.findViewById(R.id.info); info.setText("plugin.xml自定义key:"+ BundleContextFactory.getInstance().getBundleContext(). getBundle().getHeaders().get("mykey")); } }原文链接:https://www.f2er.com/xml/298766.html