apk安装法之三--"application/vnd.android.package-archive"是什么?

apk安装法之三--"application/vnd.android.package-archive"是什么?

原创  2014年08月15日 11:11:59

在第二篇中讲明了调用

[java]  view plain  copy
  1. Intent i = new Intent(Intent.ACTION_VIEW);  
  2.         i.setDataAndType(Uri.parse("file://" + apkfile.toString()), "application/vnd.android.package-archive");   
  3.         mContext.startActivity(i);  
可以自动安装一个apk应用。


但这里

[java]  view plain  copy
  1. "application/vnd.android.package-archive"究竟是什么呢?  
[java]  view plain  copy
  1. </pre><pre name="code" class="java">具体看下面这段代码  
[java]  view plain  copy
  1. <pre name="code" class="java">/** 
  2.  * 打开文件 
  3.  * @param file 
  4.  */   
  5. private void openFile(File file){   
  6.        
  7.     Intent intent = new Intent();   
  8.     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   
  9.     //设置intent的Action属性   
  10.     intent.setAction(Intent.ACTION_VIEW);   //这里的action——view之功用5下一篇博客  
  11.     //获取文件file的MIME类型   
  12.     String type = getMIMEType(file);   
  13.     //设置intent的data和Type属性。   
  14.     intent.setDataAndType(/*uri*/Uri.fromFile(file), type);   
  15.     //跳转   
  16.     startActivity(intent);     
  17.        
  18. }   
  19.    
  20. /** 
  21.  * 根据文件后缀名获得对应的MIME类型。 
  22.  * @param file 
  23.  */   
  24. private String getMIMEType(File file) {   
  25.        
  26.     String type="*/*";   
  27.     String fName = file.getName();   
  28.     //获取后缀名前的分隔符"."在fName中的位置。   
  29.     int dotIndex = fName.lastIndexOf(".");   
  30.     if(dotIndex < 0){   
  31.         return type;   
  32.     }   
  33.     /* 获取文件的后缀名*/   
  34.     String end=fName.substring(dotIndex,fName.length()).toLowerCase();   
  35.     if(end=="")return type;   
  36.     //在MIME和文件类型的匹配表中找到对应的MIME类型。   
  37.     for(int i=0;i<MIME_MapTable.length;i++){ //MIME_MapTable??在这里你一定有疑问,这个MIME_MapTable是什么?   
  38.         if(end.equals(MIME_MapTable[i][0]))   
  39.             type = MIME_MapTable[i][1];   
  40.     }          
  41.     return type;   
  42. }   
  43.    
  44.    
  45.    
  46.    
  47.    
  48.    
  49.    
  50.  由上可见,MIME_MapTable是所有文件的后缀名所对应的MIME类型的一个String数组:  
  51.    
  52. Java代码  
  53.   
  54.           final String[][] MIME_MapTable={   
  55.             //{后缀名,MIME类型}   
  56.             {".3gp",    "video/3gpp"},   
  57.             {".apk",    "application/vnd.android.package-archive"},   
  58.             {".asf",    "video/x-ms-asf"},   
  59.             {".avi",    "video/x-msvideo"},   
  60.             {".bin",    "application/octet-stream"},   
  61.             {".bmp",    "image/bmp"},   
  62.             {".c",  "text/plain"},   
  63.             {".class",  "application/octet-stream"},   
  64.             {".conf",   "text/plain"},   
  65.             {".cpp",    "text/plain"},   
  66.             {".doc",    "application/msword"},   
  67.             {".docx",   "application/vnd.openxmlformats-officedocument.wordprocessingml.document"},   
  68.             {".xls",    "application/vnd.ms-excel"},    
  69.             {".xlsx",   "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},   
  70.             {".exe",    "application/octet-stream"},   
  71.             {".gif",    "image/gif"},   
  72.             {".gtar",   "application/x-gtar"},   
  73.             {".gz""application/x-gzip"},   
  74.             {".h",  "text/plain"},   
  75.             {".htm",    "text/html"},   
  76.             {".html",   "text/html"},   
  77.             {".jar",    "application/java-archive"},   
  78.             {".java",   "text/plain"},   
  79.             {".jpeg",   "image/jpeg"},   
  80.             {".jpg",    "image/jpeg"},   
  81.             {".js""application/x-javascript"},   
  82.             {".log",    "text/plain"},   
  83.             {".m3u",    "audio/x-mpegurl"},   
  84.             {".m4a",    "audio/mp4a-latm"},   
  85.             {".m4b",    "audio/mp4a-latm"},   
  86.             {".m4p",    "audio/mp4a-latm"},   
  87.             {".m4u",    "video/vnd.mpegurl"},   
  88.             {".m4v",    "video/x-m4v"},    
  89.             {".mov",    "video/quicktime"},   
  90.             {".mp2",    "audio/x-mpeg"},   
  91.             {".mp3",    "audio/x-mpeg"},   
  92.             {".mp4",    "video/mp4"},   
  93.             {".mpc",    "application/vnd.mpohun.certificate"},          
  94.             {".mpe",    "video/mpeg"},     
  95.             {".mpeg",   "video/mpeg"},     
  96.             {".mpg",    "video/mpeg"},     
  97.             {".mpg4",   "video/mp4"},      
  98.             {".mpga",   "audio/mpeg"},   
  99.             {".msg",    "application/vnd.ms-outlook"},   
  100.             {".ogg",    "audio/ogg"},   
  101.             {".pdf",    "application/pdf"},   
  102.             {".png",    "image/png"},   
  103.             {".pps",    "application/vnd.ms-powerpoint"},   
  104.             {".ppt",    "application/vnd.ms-powerpoint"},   
  105.             {".pptx",   "application/vnd.openxmlformats-officedocument.presentationml.presentation"},   
  106.             {".prop",   "text/plain"},   
  107.             {".rc""text/plain"},   
  108.             {".rmvb",   "audio/x-pn-realaudio"},   
  109.             {".rtf",    "application/rtf"},   
  110.             {".sh""text/plain"},   
  111.             {".tar",    "application/x-tar"},      
  112.             {".tgz",    "application/x-compressed"},    
  113.             {".txt",    "text/plain"},   
  114.             {".wav",    "audio/x-wav"},   
  115.             {".wma",    "audio/x-ms-wma"},   
  116.             {".wmv",    "audio/x-ms-wmv"},   
  117.             {".wps",    "application/vnd.ms-works"},   
  118.             {".xml",    "text/plain"},   
  119.             {".z",  "application/x-compress"},   
  120.             {".zip",    "application/x-zip-compressed"},   
  121.             {"",        "*/*"}     
  122.         };   
  123.    


 
 

由上可见,

[java]  view plain  copy
  1. "application/vnd.android.package-archive"是文件类型,具体对应apk类型。  

版权声明:本文为博主原创文章,未经博主允许不得转载。
 
cidwzhu414
  • cidwzhu414
    2016-03-30 10:421楼
  • 挺详细的 竟然没人点赞!!
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值