Android 实现系统更新功能
生活随笔
收集整理的這篇文章主要介紹了
Android 实现系统更新功能
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*** 安裝新版本* @param context 當前實例上下文*/public void InstallApk(Context context,String fileName){File f = new File(BasePath.DOWNLOAD_DIR,fileName);Intent intent = new Intent();intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.setAction(android.content.Intent.ACTION_VIEW);// 調用getMIMEType()來取得MimeType String type = getMIMEType(f);//設定intent的file與MimeType
intent.setDataAndType(Uri.fromFile(f),type);context.startActivity(intent); }/*** 判斷文件MimeType的method * @param f 要判斷類型的文件* @return 文件的MiMe類型*/public String getMIMEType(File f) { String type="";String fName=f.getName();// 取得擴展名 String end=fName.substring(fName.lastIndexOf(".")+1,fName.length()).toLowerCase(); // 按擴展名的類型決定MimeType if(end.equals("m4a")||end.equals("mp3")||end.equals("mid")||end.equals("xmf")||end.equals("ogg")||end.equals("wav")){type = "audio"; }else if(end.equals("3gp")||end.equals("mp4")){type = "video";}else if(end.equals("jpg")||end.equals("gif")||end.equals("png")||end.equals("jpeg")||end.equals("bmp")){type = "image";}else if(end.equals("apk")) { // android.permission.INSTALL_PACKAGES type = "application/vnd.android.package-archive"; } else{type="*";}//如果無法直接打開,就跳出軟件清單給使用者選擇 if(end.equals("apk")) { } else { type += "/*"; } return type; }
轉載于:https://www.cnblogs.com/jRoger/articles/2671975.html
總結
以上是生活随笔為你收集整理的Android 实现系统更新功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HP刀片机远程https安装RedHat
- 下一篇: android 界面切换【转】