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")); } }