现在的位置: 首页 > 综合 > 正文

apklug插件托管服务开发教程之下载插件-02

2018年02月23日 ⁄ 综合 ⁄ 共 1870字 ⁄ 字号 评论关闭

 结合上节<按条件查询宿主中的插件>,本节下载并按照云端的插件。

实现项目demo http://git.oschina.net/plug/ApkplugCloudServiceDemo

实现代码 :com.apkplugdemo.adapter.SearchBundleAdapter

一,插件下载安装服务

    插件下载安装服务也是以OSGI服务形式提供的,获取服务的模板代码为:       

1 //查询插件下载服务 
因为该服务在框架启动时启动,所以肯定存在
2 ServiceReference
reference=context.getServiceReference(AppDownload.
class.getName());
3 if(null!=reference){
4         service=(AppDownload)
context.getService(reference);
5 }
6 context.ungetService(reference);

二,AppDownload服务接口说明  

01 public interface AppDownload
{
02     /**
03      *
插件托管服务接口
04      *
@param appBean ab    包含插件基本信息
05      *
@param mContext      android上下文
06      *
@param callback      服务回调接口
07      *
@throws IOException
08      */
09     public void download(appBean
ab,Context mContext,AppDownloadCallBack callback)
throws IOException;
10 }

三,调用插件安装服务接口下载插件

    1)首先应该获取appBean 目前有两种方式可以获取到

        1.通过插件搜索服务           即上一节提到的

        2.通过插件版本状态服务    

   2)编写回调接口AppDownloadCallBack

    

01 public interface AppDownloadCallBack
{
02     /**
03      *
安装成功
04      */
05     public final int suc_install=0;
06     /**
07      *
安装失败
08      */
09     public final int fail_install=-1;
10     /**
11      *
安装成功
12      */
13     public final int suc_download=1;
14     /**
15      *
下载失败
16      */
17     public final int fail_download=-2;
18     /**
19      *
获取url成功
20      */
21     public final int suc_url=2;
22     /**
23      *
获取url失败
24      */
25     public final int fail_url=-2;
26     /**
27      *
插件安装成功后
28      *
@param b
29      */
30     public void onInstallSuccess(int stutas,Bundle
b);
31  
32     public void onDownLoadSuccess(String
info);
33     /**
34      *
插件下载中
35      *
@param bytesWritten  已下载数据
36      *
@param totalSize     总数据大小
37      *
@param Speed         下载速度
38      *
@param bean
39      */
40     public void onProgress(int bytesWritten, int totalSize,String
Speed);
41      
42     /**
43      *
失败
44      *
@param bean
45      *
@param errorNo
46      *
@param strMsg
47      */
48     public void onFailure(int errorNo
,String strMsg);
49 }

抱歉!评论已关闭.