1. 程式人生 > >android 內部儲存 更新apk

android 內部儲存 更新apk

fileOutputStream = new FileOutputStream(file); long sum = 0; while ((lenght = inputStream.read(buf)) != -1) { fileOutputStream.write(buf,0,lenght); sum+=lenght; int progress=(int
)(sum*1.0f/total*100); listener.onDownloading(progress); } fileOutputStream.flush(); listener.onDownloadSuccess(); LogUtil.i(TAG,"onResponse over"); }catch (Exception e){ listener
.onDownloadFailed(); LogUtil.i(TAG,"onResponse Exception"+e.getMessage().toString()); }finally { try { if (inputStream != null) inputStream.close(); if (fileOutputStream != null
) fileOutputStream.close(); }catch (Exception e){ } } LogUtil.i(TAG,"onResponse 2"); } }); } /** * 設定許可權 * @param paramString * @return */ public synchronized boolean getRoot(String paramString) { Process process = null; DataOutputStream os = null; try { process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(paramString + "\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); } catch (Exception localException) { System.out.println("@@@@root cmd error:"+localException); return false; }finally { try { if (os != null) { os.close(); } process.destroy(); } catch (Exception e) { System.out.println("###root cmd error:"+e); } } return true; } /** * 從下載連結中解析出檔名 * @param url * @return */ private String getNameFromUrl(String url){ return url.substring(url.lastIndexOf("/")+1); } public interface OnDownloadListener{ /** * 下載成功 */ void onDownloadSuccess(); /** * 下載進度 * @param progess */ void onDownloading(int progess); /* *下載失敗 */ void onDownloadFailed(); } }