apkplug利用plugin.xml传递自定义属性

前端之家收集整理的这篇文章主要介绍了apkplug利用plugin.xml传递自定义属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

猜你在找的XML相关文章