当前位置: 移动技术网 > IT编程>移动开发>Android > Android多线程断点续传下载示例详解

Android多线程断点续传下载示例详解

2019年07月24日  | 移动技术网IT编程  | 我要评论

一、概述

在上一篇博文《android多线程下载示例》中,我们讲解了如何实现android的多线程下载功能,通过将整个文件分成多个数据块,开启多个线程,让每个线程分别下载一个相应的数据块来实现多线程下载的功能。多线程下载中,可以将下载这个耗时的操作放在子线程中执行,即不阻塞主线程,又符合android开发的设计规范。

但是当下载的过程当中突然出现手机卡死,或者网络中断,手机电量不足关机的现象,这时,当手机可以正常使用后,如果重新下载文件,似乎不太符合大多数用户的心理期望,那如何实现当手机可以正常联网时,基于上次断网时下载的数据来下载呢?这就是所谓的断点下载了。这篇文章主要是讲解如何实现断点下载的功能。

本文讲解的android断点下载是基于上一篇文章《android多线程下载示例》 ,本示例是在上一示例的基础上通过在下载的过程中,将下载的信息保存到andoid系统自带的数据库sqlite中,当手机出现异常情况而断开网络时,由于数据库中记录了上次下载的数据信息,当手机再次联网时,读取数据库中的信息,从上次断开下载的地方继续下载数据。好,不多说了,进入正文。

二、服务端准备

服务端的实现很简单,这里为了使下载的文件大些,我在网络上下载了有道词典来作为要下载的测试资源。将它放置在项目的webcontent目录下,并将项目发布在tomcat服务器中,具体如下图所示:

就这样,服务端算是弄好了,怎么样?很简单吧?相信大家都会的!

三、android实现

android实现部分是本文的重点,这里我们从布局开始由浅入深慢慢讲解,这里我们通过activity来显示程序的界面,以sqlite数据库来保存下载的信息,通过contentprovider来操作保存的记录信息,通过handler和message机制将子线程中的数据传递到主线程来更新ui显示。同时通过自定义监听器来实现对ui显示更新的监听操作。

1、布局实现

布局基本上和上一博文中的布局一样,没有什么大的变动,界面上自上而下放置一个textview,用来提示文本框中输入的信息,一个文本框用来输入网络中下载文件的路径,一个button按钮,点击下载文件,一个progressbar显示下载进度,一个textview显示下载的百分比。

具体布局内容如下:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:paddingbottom="@dimen/activity_vertical_margin" 
 android:paddingleft="@dimen/activity_horizontal_margin" 
 android:paddingright="@dimen/activity_horizontal_margin" 
 android:paddingtop="@dimen/activity_vertical_margin" 
 android:orientation="vertical" 
 tools:context=".mainactivity" > 
 
 <textview 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:text="下载路径" /> 
 
 <edittext 
 android:id="@+id/ed_path" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:text="http://192.168.0.170:8080/web/youdao.exe"/> 
 <button 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:text="下载" 
 android:onclick="download"/> 
 
 <progressbar 
 android:id="@+id/pb" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 style="@android:style/widget.progressbar.horizontal"/> 
 
 <textview 
 android:id="@+id/tv_info" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:gravity="center" 
 android:text="下载:0%"/> 
 
</linearlayout> 

 2、自定义progressbarlistener监听器接口

新建自定义progressbarlistener监听器接口,这个接口中定义两个方法,void getmax(int length)用来获取下载文件的长度,void getdownload(int length);用来获取每次下载的长度,这个方法中主要是在多线程中调用,子线程中获取到的数据传递到这两个接口方法中,然后在这两个接口方法中通过handler将相应的长度信息传递到主线程,更新界面显示信息。

具体代码实现如下:

package com.example.inter; 
 
/** 
 * 自定义进度条监听器 
 * @author liuyazhuang 
 * 
 */ 
public interface progressbarlistener { 
 /** 
 * 获取文件的长度 
 * @param length 
 */ 
 void getmax(int length); 
 /** 
 * 获取每次下载的长度 
 * @param length 
 */ 
 void getdownload(int length); 
} 

3.定义数据库的相关信息类downloaddbhelper

在这个实例中,我们将数据库的名称定义为download.db,我们需要保存主键id,文件下载后要保存的路径,每个线程的标识id,每个线程下载的文件数据块大小,所以,在创建的数据表中共有_id, path,threadid,downloadlength,详情见下图

downloaddbhelper实现的具体代码如下:

package com.example.db; 
 
import android.content.context; 
import android.database.sqlite.sqlitedatabase; 
import android.database.sqlite.sqlitedatabase.cursorfactory; 
import android.database.sqlite.sqliteopenhelper; 
 
/** 
 * 数据库相关类 
 * @author liuyazhuang 
 * 
 */ 
public class downloaddbhelper extends sqliteopenhelper { 
 /** 
 * 数据库名称 
 */ 
 private static final string name = "download.db"; 
 /** 
 * 原有的构造方法 
 * @param context 
 * @param name 
 * @param factory 
 * @param version 
 */ 
 public downloaddbhelper(context context, string name, 
 cursorfactory factory, int version) { 
 super(context, name, factory, version); 
 } 
 /** 
 * 重载构造方法 
 * @param context 
 */ 
 public downloaddbhelper(context context){ 
 super(context, name, null, 1); 
 } 
 
 /** 
 * 创建数据库时调用 
 */ 
 @override 
 public void oncreate(sqlitedatabase db) { 
 db.execsql("create table download(_id integer primary key autoincrement," + 
  "path text," + 
  "threadid integer," + 
  "downloadlength integer)"); 
 
 } 
 /** 
 * 更新数据库时调用 
 */ 
 @override 
 public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { 
 
 } 
 
} 

 4、创建downloadprovider类

downloadprovider类继承自contentprovider,提供操作数据库的方法,在这个类中,通过urimatcher类匹配要操作的数据库,通过downloaddbhelper对象来得到一个具体数据库实例,来对相应的数据库进行增、删、改、查操作。
具体实现如下代码所示:

package com.example.provider; 
 
import com.example.db.downloaddbhelper; 
 
import android.content.contentprovider; 
import android.content.contentvalues; 
import android.content.urimatcher; 
import android.database.cursor; 
import android.database.sqlite.sqlitedatabase; 
import android.database.sqlite.sqliteopenhelper; 
import android.net.uri; 
 
/** 
 * 自定义contentprovider实例 
 * @author liuyazhuang 
 * 
 */ 
public class downloadprovider extends contentprovider { 
 //实例化urimatcher对象 
 private static urimatcher matcher = new urimatcher(urimatcher.no_match); 
 //配置访问规则 
 private static final string authority = "download"; 
 //自定义常量 
 private static final int dowanload = 10; 
 static{ 
 //添加匹配的规则 
 matcher.adduri(authority, "download", dowanload); 
 } 
 private sqliteopenhelper mopenhelper; 
 @override 
 public boolean oncreate() { 
 mopenhelper = new downloaddbhelper(getcontext()); 
 return false; 
 } 
 
 @override 
 public cursor query(uri uri, string[] projection, string selection, 
 string[] selectionargs, string sortorder) { 
 // todo auto-generated method stub 
 cursor ret = null; 
 sqlitedatabase db = mopenhelper.getreadabledatabase(); 
 int code = matcher.match(uri); 
 switch (code) { 
 case dowanload: 
 ret = db.query("download", projection, selection, selectionargs, null, null, sortorder); 
 break; 
 
 default: 
 break; 
 } 
 return ret; 
 } 
 
 @override 
 public string gettype(uri uri) { 
 // todo auto-generated method stub 
 return null; 
 } 
 
 @override 
 public uri insert(uri uri, contentvalues values) { 
 // todo auto-generated method stub 
 sqlitedatabase db = mopenhelper.getwritabledatabase(); 
 int code = matcher.match(uri); 
 switch (code) { 
 case dowanload: 
 db.insert("download", "_id", values); 
 break; 
 
 default: 
 break; 
 } 
 return null; 
 } 
 
 @override 
 public int delete(uri uri, string selection, string[] selectionargs) { 
 sqlitedatabase db = mopenhelper.getwritabledatabase(); 
 int code = matcher.match(uri); 
 switch (code) { 
 case dowanload: 
 db.delete("download", selection, selectionargs); 
 break; 
 
 default: 
 break; 
 } 
 return 0; 
 } 
 
 @override 
 public int update(uri uri, contentvalues values, string selection, 
 string[] selectionargs) { 
 sqlitedatabase db = mopenhelper.getwritabledatabase(); 
 int code = matcher.match(uri); 
 switch (code) { 
 case dowanload: 
 db.update("download", values, selection, selectionargs); 
 break; 
 
 default: 
 break; 
 } 
 return 0; 
 } 
 
} 

5、创建downloadinfo实体类

为了使程序更加面向对象化,这里我们建立downloadinfo实体类来对数据库中的数据进行封装,downloadinfo实体类中的数据字段与数据库中的字段相对应
具体实现代码如下:

package com.example.domain; 
 
/** 
 * 支持断点续传时, 
 * 要保存到数据库的信息 
 * @author liuyazhuang 
 * 
 */ 
public class downloadinfo { 
 //主键id 
 private int _id; 
 //保存路径 
 private string path; 
 //线程的标识id 
 private string threadid; 
 //下载文件的大小 
 private int downloadsize; 
 
 public downloadinfo() { 
 super(); 
 } 
 
 public downloadinfo(int _id, string path, string threadid, int downloadsize) { 
 super(); 
 this._id = _id; 
 this.path = path; 
 this.threadid = threadid; 
 this.downloadsize = downloadsize; 
 } 
 
 public int get_id() { 
 return _id; 
 } 
 public void set_id(int _id) { 
 this._id = _id; 
 } 
 public string getpath() { 
 return path; 
 } 
 public void setpath(string path) { 
 this.path = path; 
 } 
 public string getthreadid() { 
 return threadid; 
 } 
 public void setthreadid(string threadid) { 
 this.threadid = threadid; 
 } 
 public int getdownloadsize() { 
 return downloadsize; 
 } 
 public void setdownloadsize(int downloadsize) { 
 this.downloadsize = downloadsize; 
 } 
} 

6、定义外界调用的操作数据库的方法类downloaddao

downloaddao类中封装了一系列操作数据库的方法,这个类不是直接操作数据库对象,而是通过contentresolver这个对象来调用downloadprovider中的方法来实现操作数据库的功能,这里用到了contentresolver与contentprovider这两个android中非常重要的类。contentprovider即内容提供者,主要是向外提供数据,简单理解就是一个应用程序可以通过contentprovider向外提供操作本应用程序的接口,其他应用程序可以调用contentprovider提供的接口来操作本应用程序的数据。contentresolver内容接接收者,它可以接收contentprovider的向外提供的数据。
具体代码实现如下:

package com.example.dao; 
 
import android.content.contentresolver; 
import android.content.contentvalues; 
import android.content.context; 
import android.database.cursor; 
import android.net.uri; 
 
import com.example.domain.downloadinfo; 
 
/** 
 * 保存下载文件信息的dao类 
 * @author liuyazhuang 
 * 
 */ 
public class downloaddao { 
 
 /** 
 * contentresolver对象 
 */ 
 private contentresolver cr; 
 
 public downloaddao(context context){ 
 this.cr = context.getcontentresolver(); 
 } 
 /** 
 * 保存下载信息记录 
 * @param info 
 */ 
 public void save(downloadinfo info){ 
 uri uri = uri.parse("content://download/download"); 
 contentvalues values = new contentvalues(); 
 values.put("path", info.getpath()); 
 values.put("threadid", info.getthreadid()); 
 cr.insert(uri, values); 
 } 
 
 /** 
 * 更新下载信息记录 
 * @param info 
 */ 
 public void update(downloadinfo info){ 
 uri uri = uri.parse("content://download/download"); 
 contentvalues values = new contentvalues(); 
 values.put("downloadlength", info.getdownloadsize()); 
 values.put("threadid", info.getthreadid()); 
 cr.update(uri, values, " path = ? and threadid = ? ", new string[]{info.getpath(), info.getthreadid()}); 
 } 
 /** 
 * 删除下载信息记录 
 * @param info 
 */ 
 public void delete(downloadinfo info){ 
 uri uri = uri.parse("content://download/download"); 
 cr.delete(uri, " path = ? and threadid = ? ", new string[]{info.getpath(), info.getthreadid()}); 
 } 
 /** 
 * 删除下载信息记录 
 * @param info 
 */ 
 public void delete(string path){ 
 uri uri = uri.parse("content://download/download"); 
 cr.delete(uri, " path = ? ", new string[]{path}); 
 } 
 
 /** 
 * 判断是否有下载记录 
 * @param path 
 * @return 
 */ 
 public boolean isexist(string path){ 
 boolean result = false; 
 uri uri = uri.parse("content://download/download"); 
 cursor cursor = cr.query(uri, null, " path = ? ", new string[]{path}, null); 
 if(cursor.movetonext()){ 
 result = true; 
 } 
 cursor.close(); 
 return result; 
 } 
 
 /** 
 * 计算所有的下载长度 
 * @param path 
 * @return 
 */ 
 public int querycount(string path){ 
 int count = 0; 
 uri uri = uri.parse("content://download/download"); 
 cursor cursor = cr.query(uri, new string[]{"downloadlength"}, " path = ? ", new string[]{path}, null); 
 while(cursor.movetonext()){ 
 int len = cursor.getint(0); 
 count += len; 
 } 
 cursor.close(); 
 return count; 
 } 
 /** 
 * 计算每个线程的下载长度 
 * @param path 
 * @return 
 */ 
 public int query(downloadinfo info){ 
 int count = 0; 
 uri uri = uri.parse("content://download/download"); 
 cursor cursor = cr.query(uri, new string[]{"downloadlength"}, " path = ? and threadid = ?", new string[]{info.getpath(), info.getthreadid()}, null); 
 while(cursor.movetonext()){ 
 int len = cursor.getint(0); 
 count += len; 
 } 
 cursor.close(); 
 return count; 
 } 
} 

7、自定义线程类downthread

这里通过继承thread的方式来实现自定义线程操作,在这个类中主要是实现文件的下载操作,在这个类中,定义了一系列与下载有关的实例变量来控制下载的数据,通过自定义监听器progressbarlistener中的void getdownload(int length)方法来跟新界面显示的进度信息,同时通过调用downloaddao的方法来记录和更新数据的下载信息。
具体实现代码如下:

package com.example.download; 
 
import java.io.file; 
import java.io.inputstream; 
import java.io.randomaccessfile; 
import java.net.httpurlconnection; 
import java.net.url; 
 
import android.content.context; 
 
import com.example.dao.downloaddao; 
import com.example.domain.downloadinfo; 
import com.example.inter.progressbarlistener; 
 
/** 
 * 自定义线程类 
 * @author liuyazhuang 
 * 
 */ 
public class downloadthread extends thread { 
 //下载的线程id 
 private int threadid; 
 //下载的文件路径 
 private string path; 
 //保存的文件 
 private file file; 
 //下载的进度条更新的监听器 
 private progressbarlistener listener; 
 //每条线程下载的数据量 
 private int block; 
 //下载的开始位置 
 private int startposition; 
 //下载的结束位置 
 private int endposition; 
 
 private downloaddao downloaddao; 
 
 public downloadthread(int threadid, string path, file file, progressbarlistener listener, int block, context context) { 
 this.threadid = threadid; 
 this.path = path; 
 this.file = file; 
 this.listener = listener; 
 this.block = block; 
 this.downloaddao = new downloaddao(context); 
 this.startposition = threadid * block; 
 this.endposition = (threadid + 1) * block - 1; 
 } 
 
 @override 
 public void run() { 
 super.run(); 
 try { 
 //判断该线程是否有下载记录 
 downloadinfo info = new downloadinfo(); 
 info.setpath(path); 
 info.setthreadid(string.valueof(threadid)); 
 int length = downloaddao.query(info); 
 startposition += length; 
 //创建randomaccessfile对象 
 randomaccessfile accessfile = new randomaccessfile(file, "rwd"); 
 //跳转到开始位置 
 accessfile.seek(startposition); 
 url url = new url(path); 
 //打开http链接 
 httpurlconnection conn = (httpurlconnection) url.openconnection(); 
 //设置超时时间 
 conn.setconnecttimeout(5000); 
 //指定请求方式为get方式 
 conn.setrequestmethod("get"); 
 //指定下载的位置 
 conn.setrequestproperty("range", "bytes="+startposition + "-" + endposition); 
 //不用再去判断状态码是否为200 
 inputstream in = conn.getinputstream(); 
 byte[] buffer = new byte[1024]; 
 int len = 0; 
 //该线程下载的总数据量 
 int count = length; 
 while((len = in.read(buffer)) != -1){ 
 accessfile.write(buffer, 0, len); 
 //更新下载进度 
 listener.getdownload(len); 
 count += len; 
 info.setdownloadsize(count); 
 //更新下载的信息 
 downloaddao.update(info); 
 } 
 accessfile.close(); 
 in.close(); 
 } catch (exception e) { 
 // todo: handle exception 
 e.printstacktrace(); 
 } 
 } 
} 

8、新建下载的管理类downloadmanager

这个类主要是对下载过程的管理,包括下载设置下载后文件要保存的位置,计算多线程中每个线程的数据下载量等等,同时相比《android多线程下载示例》一文中,它多了多下载数据的记录与更新操作。
具体实现代码如下:

package com.example.download; 
 
import java.io.file; 
import java.io.randomaccessfile; 
import java.net.httpurlconnection; 
import java.net.url; 
 
import android.content.context; 
import android.os.environment; 
 
import com.example.dao.downloaddao; 
import com.example.domain.downloadinfo; 
import com.example.inter.progressbarlistener; 
 
/** 
 * 文件下载管理器 
 * @author liuyazhuang 
 * 
 */ 
public class downloadmanager { 
 //下载线程的数量 
 private static final int tread_size = 3; 
 private file file; 
 private downloaddao downloaddao; 
 private context context; 
 public downloadmanager(context context) { 
 this.context = context; 
 this.downloaddao = new downloaddao(context); 
 } 
 
 /** 
 * 下载文件的方法 
 * @param path:下载文件的路径 
 * @param listener:自定义的下载文件监听接口 
 * @throws exception 
 */ 
 public void download(string path, progressbarlistener listener) throws exception{ 
 url url = new url(path); 
 httpurlconnection conn = (httpurlconnection) url.openconnection(); 
 conn.setconnecttimeout(5000); 
 conn.setrequestmethod("get"); 
 if(conn.getresponsecode() == 200){ 
 int filesize = conn.getcontentlength(); 
 //设置进度条的最大长度 
 listener.getmax(filesize); 
 //判断下载记录是否存在 
 boolean ret = downloaddao.isexist(path); 
 if(ret){ 
 //得到下载的总长度,设置进度条的刻度 
 int count = downloaddao.querycount(path); 
 listener.getdownload(count); 
 }else{ 
 //保存下载记录 
 for(int i = 0; i < filesize; i++){ 
  downloadinfo info = new downloadinfo(); 
  info.setpath(path); 
  info.setthreadid(string.valueof(i)); 
  //保存下载的记录信息 
  downloaddao.save(info); 
 } 
 } 
 //创建一个和服务器大小一样的文件 
 file = new file(environment.getexternalstoragedirectory(), this.getfilename(path)); 
 randomaccessfile accessfile = new randomaccessfile(file, "rwd"); 
 accessfile.setlength(filesize); 
 //要关闭randomaccessfile对象 
 accessfile.close(); 
 
 //计算出每条线程下载的数据量 
 int block = filesize % tread_size == 0 ? (filesize / tread_size) : (filesize / tread_size +1 ); 
 
 //开启线程下载 
 for(int i = 0; i < tread_size; i++){ 
 new downloadthread(i, path, file, listener, block, context).start(); 
 } 
 } 
 } 
 
 /** 
 * 截取路径中的文件名称 
 * @param path:要截取文件名称的路径 
 * @return:截取到的文件名称 
 */ 
 private string getfilename(string path){ 
 return path.substring(path.lastindexof("/") + 1); 
 } 
} 

9、完善mainactivity

在这个类中首先,找到页面中的各个控件,实现button按钮的onclick事件,在onclick事件中开启一个线程进行下载操作,同时子线程中获取到的数据,通过handler与message机制传递到主线程,更新界面显示,利用downloaddao类中的方法来记录和更新下载数据。
具体实现代码如下:

package com.example.multi; 
 
import android.app.activity; 
import android.os.bundle; 
import android.os.handler; 
import android.os.message; 
import android.view.menu; 
import android.view.view; 
import android.widget.edittext; 
import android.widget.progressbar; 
import android.widget.textview; 
import android.widget.toast; 
 
import com.example.dao.downloaddao; 
import com.example.download.downloadmanager; 
import com.example.inter.progressbarlistener; 
 
/** 
 * mainactivity整个应用程序的入口 
 * @author liuyazhuang 
 * 
 */ 
public class mainactivity extends activity { 
 
 protected static final int error_download = 0; 
 protected static final int set_progress_max = 1; 
 protected static final int update_progress = 2; 
 
 private edittext ed_path; 
 private progressbar pb; 
 private textview tv_info; 
 private downloadmanager manager; 
 private downloaddao downloaddao; 
 
 //handler操作 
 private handler mhandler = new handler(){ 
 
 public void handlemessage(android.os.message msg) { 
 switch (msg.what) { 
 case error_download: 
 //提示用户下载失败 
 toast.maketext(mainactivity.this, "下载失败", toast.length_short).show(); 
 break; 
 case set_progress_max: 
 //得到最大值 
 int max = (integer) msg.obj; 
 //设置进度条的最大值 
 pb.setmax(max); 
 break; 
 case update_progress: 
 //获取当前下载的长度 
 int currentprogress = pb.getprogress(); 
 //获取新下载的长度 
 int len = (integer) msg.obj; 
 //计算当前总下载长度 
 int crrrenttotalprogress = currentprogress + len; 
 pb.setprogress(crrrenttotalprogress); 
  
 //获取总大小 
 int maxprogress = pb.getmax(); 
 //计算百分比 
 float value = (float)currentprogress / (float)maxprogress; 
 int percent = (int) (value * 100); 
 //显示下载的百分比 
 tv_info.settext("下载:"+percent+"%"); 
  
 if(maxprogress == crrrenttotalprogress){ 
  //删除下载记录 
  downloaddao.delete(ed_path.gettext().tostring()); 
 } 
 break; 
 default: 
 break; 
 } 
 }; 
 }; 
 @override 
 protected void oncreate(bundle savedinstancestate) { 
 super.oncreate(savedinstancestate); 
 setcontentview(r.layout.activity_main); 
 this.ed_path = (edittext) super.findviewbyid(r.id.ed_path); 
 this.pb = (progressbar) super.findviewbyid(r.id.pb); 
 this.tv_info = (textview) super.findviewbyid(r.id.tv_info); 
 this.manager = new downloadmanager(this); 
 this.downloaddao = new downloaddao(this); 
 } 
 
 @override 
 public boolean oncreateoptionsmenu(menu menu) { 
 // inflate the menu; this adds items to the action bar if it is present. 
 getmenuinflater().inflate(r.menu.main, menu); 
 return true; 
 } 
 
 public void download(view v){ 
 final string path = ed_path.gettext().tostring(); 
 //下载 
 new thread(new runnable() { 
 @override 
 public void run() { 
 // todo auto-generated method stub 
 try { 
  manager.download(path, new progressbarlistener() { 
  @override 
  public void getmax(int length) { 
  // todo auto-generated method stub 
  message message = new message(); 
  message.what = set_progress_max; 
  message.obj = length; 
  mhandler.sendmessage(message); 
  } 
  
  @override 
  public void getdownload(int length) { 
  // todo auto-generated method stub 
  message message = new message(); 
  message.what = update_progress; 
  message.obj = length; 
  mhandler.sendmessage(message); 
  } 
  }); 
 } catch (exception e) { 
  // todo: handle exception 
  e.printstacktrace(); 
  message message = new message(); 
  message.what = error_download; 
  mhandler.sendmessage(message); 
 } 
 } 
 }).start(); 
 } 
} 

10、增加权限

最后,别忘了给应用授权,这里要用到android联网授权和向sd卡中写入文件的权限。
具体实现如下:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
 package="com.example.multi" 
 android:versioncode="1" 
 android:versionname="1.0" > 
 
 <uses-sdk 
 android:minsdkversion="8" 
 android:targetsdkversion="18" /> 
 <uses-permission android:name="android.permission.internet"/> 
 <uses-permission android:name="android.permission.mount_unmount_filesystems"/> 
 <uses-permission android:name="android.permission.write_external_storage"/> 
 <application 
 android:allowbackup="true" 
 android:icon="@drawable/ic_launcher" 
 android:label="@string/app_name" 
 android:theme="@style/apptheme" > 
 <activity 
 android:name="com.example.multi.mainactivity" 
 android:label="@string/app_name" > 
 <intent-filter> 
 <action android:name="android.intent.action.main" /> 
 
 <category android:name="android.intent.category.launcher" /> 
 </intent-filter> 
 </activity> 
 <provider android:name="com.example.provider.downloadprovider" android:authorities="download"></provider> 
 </application> 
 
</manifest> 

四、运行效果

如上:实现了android中的断点下载功能。
提醒:大家可以到来获取完整的

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网