案例:

首先,我们先看看Android如何利用第三方应用程序打开PDF文件

      File tempFile = new File(path);        if (!tempFile.exists()) {            return;        }        try {     *//*       Intent intent = new Intent("android.intent.action.VIEW");            intent.addCategory("android.intent.category.DEFAULT");*//*            Intent intent = new Intent(Intent.ACTION_VIEW);            Uri data = Uri.fromFile(tempFile);            intent.setDataAndType(data, "application/pdf");            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);            startActivity(intent);            finish();        } catch (ActivityNotFoundException ae) {            _projectUploadDetails_WebView.loadUrl("");            try {                _projectUploadDetails_WebView.removeView(docView);            } catch (Exception e) {            }            if (path.toLowerCase().endsWith(".pdf")) {                OpenPdf(path);            }        }

其中我们看到了intent

Intent设置setDataAndType,对跳转的传输的数据和类型进行设置。


其中我们还要分清uri url urn  path的区别

URI,是uniform resource identifier,统一资源标识符,用来唯一的标识一个资源。

URL是uniform resource locator,统一资源定位器,它是一种具体的URI,即URL可以用来标识一个资源,而且还指明了如何locate这个资源。

URN,uniform resource name,统一资源命名,是通过名字来标识资源。

URI是以一种抽象的,高层次概念定义统一资源标识,而URL和URN则是具体的资源标识的方式。URL和URN都是一种URI。

总结:URL是一种具体的URI,它不仅唯一标识资源,而且还提供了定位该资源的信息。URI是一种语义上的抽象概念,可以是绝对的,也可以是相对的,而URL则必须提供足够的信息来定位。

path  文件保存路径

我们可以根据以下的数据类型选择


            //{后缀名,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"}, 
            {"",        "*/*"}   
        }; 


关键词:Intent   Uri   setDataAndType(data,type);





更多相关文章

  1. Android(安卓)学习资源-博客篇
  2. 一些非常实用的 Android(安卓)开发资源 【转】
  3. Android应用开发中的风格和主题(style,themes)
  4. Android(安卓)如何查找最佳匹配资源
  5. Android系列之Wifi定位
  6. 手把手搭建 android 开发环境||资源打包下载【更新到android 4.2
  7. 一些非常实用的 Android(安卓)开发资源
  8. Android系列之Wifi定位
  9. Android(安卓)APK反编译查看源码及资源文件

随机推荐

  1. Android调用webservice
  2. Android上最好的第三方浏览器有哪些不错
  3. android应用程序分享,蓝牙文件传输(代码)
  4. iOS vs. Android,应用设计该如何对症下药?
  5. Android(安卓)资源(resource)学习小结
  6. Android(安卓)播放Gif 动画
  7. Android基于Sensor感应器获取重力感应加
  8. Android新手入门 FAQ
  9. Android的线程和线程池
  10. Android日志系统Logcat源代码简要分析