案例:

首先,我们先看看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 开发环境||资源打包下载【更新到android 4.2
  3. 一些非常实用的 Android 开发资源
  4. Android APK反编译查看源码及资源文件
  5. Drawable资源
  6. 【Android Studio】Resource Shrinking去掉无用的资源
  7. android-google开源资源

随机推荐

  1. android NDK 开发环境配置
  2. Android旋转屏幕后国际化语言失效的解决
  3. android4.2 修改设置背景
  4. Android declare-styleable:自定义控件的
  5. Error:No resource identifier found for
  6. 获取手机安装的全部应用的示例教程
  7. :activity状态的保存和保持
  8. Android中两种设置全屏的方法
  9. 6.1、Android中从Internet获取数据
  10. Android providers 解析之telephony