Android-你还在用downloadmanager更新下载-out了!!!

轻松搞定下载MyDownloadManager
序言:

     软件更新想必大家都用过,很多是用友盟的下载,但是也有自己公司服务器下载的处理方式,本文主要讲解的是自己下载的处理方法
      想必大家就会说,这还用自己做呀,系统自带的一行代码不就解决了-------DownloadManager,如果你还在用这个下载,那你就太年轻了,不是说这个方法不好,而是在中国这样的大环境下********你懂的,三星note系列部分手机需要手动打开这个权限才能用这个功能(确定不是逗我????),而有些国产手机更加nb了直接个阉割了(nm)
       好吧,既然这样还是规规矩矩的自己写吧,同样的需求我标示ios分分钟搞定,咱们这边无数的坑呀,废话到处结束!咱们看如何自己写一个DownloadManager!先上效果



流程:

     正常的逻辑我们需要先通过服务器判断是否需要更新软件,然后如果需要则返回一个url下载链接,下载安装更新

实现:

1.获取更新的url然后启动服务后台下载

      

2.后台服务器中启动下载和通知

下载使用的是xutils,大家可以自己替换你自己喜欢的下载框架(自己写也是可以的!!!)

3.在onlading中更新通知栏更新就行了!下载完成或者错误以后停止后台服务然后关闭通知栏通知信息



4.安装apk



最后啰嗦几句关于布局文件中的progressbar自定义背景(如果是处女座请详细学习这些属性的差别吧!)
第一种:

第二种:

第一种的实现方式是优化的实现:

第二种:



5.需要注意的细节:
  1. 启动服务的时候千万别用action的方式去启动,部分手机无法启动(Galaxy A8亲测不好用呀)
  2. 憋忘记添加网络权限和本地文件读写权限
  3. 记得关闭服务




  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
android好书系列,我目前找了两本,先贡献给大家。以后如果有好的资源,再上传和大家分享。 本资源是第一本。 这是一本学习android的好书,我浏览了,是老外著的,高清晰的pdf。为了方便大家学习android,我将本书所附的源码一块打包了。方便了不少,如果觉得好就顶一下吧,大家共同进步。 另外一本pro android下载地址: http://download.csdn.net/source/3139707 本书的目录结构如下: Chapter 1: The Big Picture Challenges of Smartphone Programming What Androids Are Made Of Stuff at Your Disposal ■Chapter 2: Projects and Targets Pieces and Parts Creating a Project Project Structure Root Contents The Sweat Off Your Brow And Now, the Rest of the Story What You Get Out of It Inside the Manifest In the Beginning, There Was the Root, And It Was Good Permissions, Instrumentations, and Applications (Oh My!) Your Application Does Something, Right? Achieving the Minimum Version=Control Emulators and Targets Virtually There Aiming at a Target ■Chapter 3: Creating a Skeleton Application Begin at the Beginning Dissecting the Activity Building and Running the Activity ■Chapter 4: Using XML-Based Layouts What Is an XML-Based Layout? Why Use XML-Based Layouts? OK, So What Does It Look Like? What’s with the @ Signs? And How Do We Attach These to the Java? The Rest of the Story ■Chapter 5: Employing Basic Widgets Assigning Labels Button, Button, Who’s Got the Button? Fleeting Images Fields of Green Or Other Colors Just Another Box to Check Turn the Radio Up It’s Quite a View Useful Properties Useful Methods Colors ■Chapter 6: Working with Containers Thinking Linearly LinearLayout Concepts and Properties LinearLayout Example All Things Are Relative RelativeLayout Concepts and Properties RelativeLayout Example Tabula Rasa TableLayout Concepts and Properties TableLayout Example Scrollwork ■Chapter 7: Using Selection Widgets Adapting to the Circumstances Lists of Naughty and Nice Spin Control Grid Your Lions (or Something Like That) Fields: Now with 35% Less Typing! Galleries, Give or Take the Art ■Chapter 8: Getting Fancy with Lists Getting to First Base A Dynamic Presentation Better Stronger Faster Using

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值