在第二篇中讲明了调用

Intent i = new Intent(Intent.ACTION_VIEW);i.setDataAndType(Uri.parse("file://" + apkfile.toString()), "application/vnd.android.package-archive"); mContext.startActivity(i);

可以自动安装一个apk应用。

但这里

"application/vnd.android.package-archive"究竟是什么呢?
</pre><pre name="code" class="java">具体看下面这段代码
<pre name="code" class="java">/*** 打开文件* @param file*/
private void openFile(File file){ Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //设置intent的Action属性 intent.setAction(Intent.ACTION_VIEW);   //这里的action——view之功用5下一篇博客//获取文件file的MIME类型 String type = getMIMEType(file); //设置intent的data和Type属性。 intent.setDataAndType(/*uri*/Uri.fromFile(file), type); //跳转 startActivity(intent);   } /*** 根据文件后缀名获得对应的MIME类型。* @param file*/
private String getMIMEType(File file) { String type="*/*"; String fName = file.getName(); //获取后缀名前的分隔符"."在fName中的位置。 int dotIndex = fName.lastIndexOf("."); if(dotIndex < 0){ return type; } /* 获取文件的后缀名*/ String end=fName.substring(dotIndex,fName.length()).toLowerCase(); if(end=="")return type; //在MIME和文件类型的匹配表中找到对应的MIME类型。 for(int i=0;i<MIME_MapTable.length;i++){ //MIME_MapTable??在这里你一定有疑问,这个MIME_MapTable是什么? if(end.equals(MIME_MapTable[i][0])) type = MIME_MapTable[i][1]; }        return type;
} 由上可见,MIME_MapTable是所有文件的后缀名所对应的MIME类型的一个String数组:Java代码final String[][] MIME_MapTable={ //{后缀名,MIME类型} {".3gp",    "video/3gpp"}, {".apk",    "application/vnd.android.package-archive"}, {".asf",    "video/x-ms-asf"}, {".avi",    "video/x-msvideo"}, {".bin",    "application/octet-stream"}, {".bmp",    "image/bmp"}, {".c",  "text/plain"}, {".class",  "application/octet-stream"}, {".conf",   "text/plain"}, {".cpp",    "text/plain"}, {".doc",    "application/msword"}, {".docx",   "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}, {".xls",    "application/vnd.ms-excel"},  {".xlsx",   "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}, {".exe",    "application/octet-stream"}, {".gif",    "image/gif"}, {".gtar",   "application/x-gtar"}, {".gz", "application/x-gzip"}, {".h",  "text/plain"}, {".htm",    "text/html"}, {".html",   "text/html"}, {".jar",    "application/java-archive"}, {".java",   "text/plain"}, {".jpeg",   "image/jpeg"}, {".jpg",    "image/jpeg"}, {".js", "application/x-javascript"}, {".log",    "text/plain"}, {".m3u",    "audio/x-mpegurl"}, {".m4a",    "audio/mp4a-latm"}, {".m4b",    "audio/mp4a-latm"}, {".m4p",    "audio/mp4a-latm"}, {".m4u",    "video/vnd.mpegurl"}, {".m4v",    "video/x-m4v"},  {".mov",    "video/quicktime"}, {".mp2",    "audio/x-mpeg"}, {".mp3",    "audio/x-mpeg"}, {".mp4",    "video/mp4"}, {".mpc",    "application/vnd.mpohun.certificate"},        {".mpe",    "video/mpeg"},   {".mpeg",   "video/mpeg"},   {".mpg",    "video/mpeg"},   {".mpg4",   "video/mp4"},    {".mpga",   "audio/mpeg"}, {".msg",    "application/vnd.ms-outlook"}, {".ogg",    "audio/ogg"}, {".pdf",    "application/pdf"}, {".png",    "image/png"}, {".pps",    "application/vnd.ms-powerpoint"}, {".ppt",    "application/vnd.ms-powerpoint"}, {".pptx",   "application/vnd.openxmlformats-officedocument.presentationml.presentation"}, {".prop",   "text/plain"}, {".rc", "text/plain"}, {".rmvb",   "audio/x-pn-realaudio"}, {".rtf",    "application/rtf"}, {".sh", "text/plain"}, {".tar",    "application/x-tar"},    {".tgz",    "application/x-compressed"},  {".txt",    "text/plain"}, {".wav",    "audio/x-wav"}, {".wma",    "audio/x-ms-wma"}, {".wmv",    "audio/x-ms-wmv"}, {".wps",    "application/vnd.ms-works"}, {".xml",    "text/plain"}, {".z",  "application/x-compress"}, {".zip",    "application/x-zip-compressed"}, {"",        "*/*"}   }; 

由上可见,

"application/vnd.android.package-archive"是文件类型,具体对应apk类型。

apk安装法之三--application/vnd.android.package-archive是什么?相关推荐

  1. android pptx mime类型,application/vnd.android.package-archive是Apk的MIME类型

    final String[][] MIME_MapTable={ //{后缀名,MIME类型} {".3gp","video/3gpp"}, {".a ...

  2. 20_Android中apk安装器,通过WebView来load进一个页面,Android通知,程序退出自动杀死进程,通过输入包名的方式杀死进程

     场景:实现安装一个apk应用程序的过程.界面如下: 编写如下应用,应用结构如下: <RelativeLayout xmlns:android="http://schemas.an ...

  3. Android 下载APK 安装APK 打开APK

    今天有了一个这样的需求 :下载一个apk文件,然后当你下载完成后,按钮的文字发生改变,变成点击安装,然后安装完成之后,变成打开. 这是下载apk的方法: ? 1 2 3 4 5 6 7 8 9 10 ...

  4. android 7 apk 安装程序,Android 7.0 apk安装

    简介 Android 7.0开始,系统修改了安全机制: 限定应用在默认情况下只能访问自身应用数据.所以当我们想通过File对象访问其它package数据时,就需要借助于ContentProvider. ...

  5. Android开发之下载Apk安装的方法兼容Android7.0和8.0及以上

    具体查看代码: 首先在清单文件配置三个权限读写权限和请求安装权限(兼容Android8.0手机)如下: <!--安装apk权限--><uses-permission android: ...

  6. android 7 apk 安装程序,Android安装apk文件并适配Android 7.0详解

    Android安装apk文件并适配Android 7.0详解 首先在AndroidManifest.xml文件,activity同级节点注册provider: android:name="a ...

  7. android 下载apk安装后自动启动,下载apk并启动安装

    本篇实现现在网络上的apk并启动安装程序. #### 权限 写入权限和网络访问权限 ~~~ ~~~ #### 变量 ~~~ private DownloadManager downloadManage ...

  8. android apk安装引导,Android-调用系统安装apk

    对于7.0及其以上的设备我们需要做如下操作: 1.在manifest中注册FileProvider android:name="android.support.v4.content.File ...

  9. android apk安装过程,Android安装apk文件并适配Android 7.0详解

    Android安装apk文件并适配Android 7.0详解 首先在AndroidManifest.xml文件,activity同级节点注册provider: android:name="a ...

最新文章

  1. 一个让Python代码运行更快的最佳方式!
  2. Spring基础专题——第十章(基础注解编程——下)
  3. R语言基于Boruta进行机器学习特征筛选(Feature Selection)
  4. Automatic IE Testing With Python
  5. 自然常数 e 的理解与应用
  6. matlab怎么调整子图间距,matplotlib调整子图间距,调整整体空白的方法
  7. Linux 关机/关闭主机/关闭系统/重启系统/注销系统的命令
  8. CPaintDC、CClientDC、CWindowDC和CMetaFileDC类的主要特点及区别-Windows绘图基础知识
  9. java 下载管理_Java多线程文件下载管理器详解
  10. 导入php项目_商业裂变,之项目技术实战(第九节:程序框架的安装)
  11. play 1.2.4的action执行前后的加载逻辑
  12. wps怎么把当前页面设置为横向_办公软件操作技巧011:如何将word文档的部分页面改为横向...
  13. 读书篇:《细说PHP》四、数组
  14. C51与MDK共存 Keil5安装教程 WIN10 亲测可用
  15. Linux:DNS域名解析服务
  16. 在veu开发项目中 关闭eslint代码校验
  17. 数据分析|爬取14455个基金,千万别被人当成韭菜给割了
  18. read和write阻塞和非阻塞方面的理解
  19. 向指定的excel文件中追加数据
  20. 视觉打标软件 在线视觉打标系统 1.金橙子控制板卡 2.自主研发的定位系统

热门文章

  1. 经典论文翻译--Minimum Snap Trajectory Generation and Control for Quadrotors
  2. 爬取网页文本数据--Python
  3. C++笔试题大全----下
  4. php 5.3.29 nts,为什么PHP 5.3不在支持ISAPI,为什么还要分NTS和TS版本?
  5. 微信小程序 请求数据
  6. AP发现AC过程——CAPWAP协议详解
  7. HTML+CSS大作业: 抗击疫情网页制作作业_疫情防控网页设计模板HTML_ 简单学生网页设_静态HTML+CSS网站制作成品...
  8. Pytorch提取预训练模型特定中间层的输出
  9. 关于CTC模型的理解
  10. NAS网络存储中使用Docker安装百度网盘客户端教程