<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<!-- 插件平台须要的配置! -->
<activity
android:name="org.apkplug.app.apkplugActivity"
android:theme="@style/android:Theme.Light"
android:configChanges="orientation|keyboardHidden"
/>
三 启动apkplug框架
你能够在应用的Application中启动框架具体代码以下 (并不限制在Application中)
public FrameworkInstance start( List activatorList,Context appContext,PropertyInstance property)
public FrameworkInstance start( List activatorList,Context appContext,PropertyInstance property,DisplayMetrics dm2)
1.activatorList 是一个BundleActivator的List(能够为null) 这些BundleActivator在框架启动时启动(系统级别)
2.PropertyInstance 框架保存配置信息的接口
//框架经过该接口获取本地保存的变量
public String getProperty(String key);
//框架经过该接口设置本地变量
public void setProperty(String key,String v);
//框架启动时将自动安装该该函数提供的文件 "file:"+apk文件路径 (1.6.7之后不建议使用 可用BundleControl代替)
public String[] AutoInstall();
//框架启动时将自动安装并启动该该函数提供的文件 "file:"+apk文件路径 (1.6.7之后不建议使用 可用BundleControl代替)
public String[] AutoStart();
//调试模式 调试模式中退出APP时调用FrameworkInstance.shutdown();将删除全部插件
public boolean Debug();
四 框架启动成功获取FrameworkInstance接口
框架启动成功之后会返回org.apkplug.app.FrameworkInstance接口,它是宿主应用与apkplug框架和插件通讯的接口。
//中止框架
public void shutdown();
//获取框架的SystemBundle apkplug框架启动时会建立一个SystemBundle 它的BundleID为0 同时它不可中止和卸载,咱们科经过它与其余插件通讯
public Bundle getSystemBundle();
//SystemBundle 插件的上下文 BundleContext
public BundleContext getSystemBundleContext();
启动代码:
try
{
FrameworkInstance frame=FrameworkFactory.getInstance().start(null,Launcher.this,MyProperty.getInstance(this.getApplicationContext()));
}catch (Exception ex){
System.err.println("Could not create : " + ex);
ex.printStackTrace();
StringBuffer buf=new StringBuffer();
buf.append("插件平台启动失败:\n");
buf.append(ex.getMessage());
Toast.makeText(this, "插件平台启动失败",Toast.LENGTH_SHORT).show();
}
至此框架便嵌入到应用中并启动成功了,下一篇文章将讲解怎样经过SystemBundle获取已插件和信息等操做