Android开发:启动应用的数据库初始化和版本更新
| [日期:2011-08-18] |
来源:Linux社区
作者:anskya520 |
[字体:大 中 小]
|
下载远程apk的类:
- public class DownLoadService {
-
-
-
-
-
-
- public static File getFile(String urlpath) throws Exception{
- Thread.sleep(5000);
- URL url = new URL(urlpath);
- File file = null;
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setConnectTimeout(5000);
- InputStream ins = conn.getInputStream();
-
- if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
- file = new File(Environment.getExternalStorageDirectory(),"update.apk");
- FileOutputStream fos = new FileOutputStream(file);
- byte[] buffer = new byte[1024];
- int len;
- while((len=ins.read(buffer))!=-1){
- fos.write(buffer, 0, len);
- }
- ins.close();
- fos.close();
- }
- else{
- throw new Exception("sd卡不可读写");
- }
- return file;
- }
- }
