你好,游客 登录 注册 搜索
背景:
阅读新闻

Android开发:启动应用的数据库初始化和版本更新

[日期:2011-08-18] 来源:Linux社区  作者:anskya520 [字体:大 中 小]
下载远程apk的类:
  1. public class DownLoadService {  
  2. /** 
  3.  *   
  4.  * @param urlpath 要下载文件的地址,下载到sdcard 
  5.  * @return 
  6.  * @throws Exception 
  7.  */  
  8.      public static File getFile(String urlpath) throws Exception{  
  9.          Thread.sleep(5000);  
  10.          URL url = new URL(urlpath);  
  11.          File file = null;  
  12.          HttpURLConnection conn =  (HttpURLConnection) url.openConnection();  
  13.          conn.setConnectTimeout(5000);  
  14.          InputStream ins =  conn.getInputStream();  
  15.          //把他写到文件里面   
  16.          if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){  
  17.              file = new File(Environment.getExternalStorageDirectory(),"update.apk");  
  18.              FileOutputStream fos = new FileOutputStream(file);  
  19.              byte[] buffer = new byte[1024];  
  20.              int len;  
  21.              while((len=ins.read(buffer))!=-1){  
  22.                  fos.write(buffer, 0, len);  
  23.              }  
  24.              ins.close();  
  25.              fos.close();  
  26.          }  
  27.          else{  
  28.              throw new Exception("sd卡不可读写");  
  29.          }  
  30.          return file;  
  31.      }  
  32. }  
linux
相关资讯       Android开发 
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* 朱洋洋 发表于 2012/6/27 10:11:08
想问一下,你将数据库版本号定义在 string.xml文件里面了吗?String path = getApplicationContext().getResources().getString(
R.string.server_url); 得到的是服务器路径还是版本号?有点不懂。。。