结合上节<按条件查询宿主中的插件>,本节下载并按照云端的插件。
实现项目demo http://git.oschina.net/plug/ApkplugCloudServiceDemo
实现代码 :com.apkplugdemo.adapter.SearchBundleAdapter
一,插件下载安装服务
插件下载安装服务也是以OSGI服务形式提供的,获取服务的模板代码为:
2 |
ServiceReference
reference=context.getServiceReference(AppDownload. class .getName()); |
4 |
service=(AppDownload)
context.getService(reference); |
6 |
context.ungetService(reference); |
二,AppDownload服务接口说明
01 |
public interface AppDownload
{ |
04 |
*
@param appBean ab 包含插件基本信息 |
05 |
*
@param mContext android上下文 |
06 |
*
@param callback 服务回调接口 |
09 |
public void download(appBean
ab,Context mContext,AppDownloadCallBack callback) throws IOException; |
三,调用插件安装服务接口下载插件
1)首先应该获取appBean 目前有两种方式可以获取到
1.通过插件搜索服务 即上一节提到的
2.通过插件版本状态服务
2)编写回调接口AppDownloadCallBack
01 |
public interface AppDownloadCallBack
{ |
05 |
public final int suc_install= 0 ; |
09 |
public final int fail_install=- 1 ; |
13 |
public final int suc_download= 1 ; |
17 |
public final int fail_download=- 2 ; |
21 |
public final int suc_url= 2 ; |
25 |
public final int fail_url=- 2 ; |
30 |
public void onInstallSuccess( int stutas,Bundle
b); |
32 |
public void onDownLoadSuccess(String
info); |
35 |
*
@param bytesWritten 已下载数据 |
36 |
*
@param totalSize 总数据大小 |
40 |
public void onProgress( int bytesWritten, int totalSize,String
Speed); |
48 |
public void onFailure( int errorNo
,String strMsg); |