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

   plugin.xml文件除了定义插件属性外,开发者也能够根据本身需求添加自定义的属性。 java

demo源码下载地址 http://git.oschina.net/plug/apkplugBundles/tree/master/PluginDemo git

1.配置代码以下 ide

<?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 this

3.编写 com.apkplug.plugindemo.SimpleBundle implements BundleActivator url

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 .net

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"));
	}
}
相关文章
相关标签/搜索