android下支持pdf、ppt等格式的下载

来源:互联网 发布:无法映射网络驱动器 编辑:程序博客网 时间:2024/05/22 06:08

点击(此处)折叠或打开

  1. private static void checkCanHandleDownload(Context context, String mimeType, int destination,
  2.             boolean isPublicApi) throws GenerateSaveFileError {
  3.         if (isPublicApi) {
  4.             return;
  5.         }
  6.         Log.d(\"baron\",\"mimeType=\" + mimeType);//add by Hubin 2013/05/07

  7.         if (destination == Downloads.Impl.DESTINATION_EXTERNAL
  8.                 || destination == Downloads.Impl.DESTINATION_CACHE_PARTITION_PURGEABLE) {
  9.             if (mimeType == null) {
  10.                 throw new GenerateSaveFileError(Downloads.Impl.STATUS_NOT_ACCEPTABLE,
  11.                         \"external download with no mime type not allowed\");
  12.             }
  13.             
  14.             
  15.             //to support pdf/doc/docx/xls/xlsx/ppt/pptx format downloading
  16.             if(mimeType.trim().equalsIgnoreCase(\"application/pdf\")
  17.                 || mimeType.trim().equalsIgnoreCase(\"application/msword\")
  18.                 || mimeType.trim().equalsIgnoreCase(\"application/vnd.openxmlformats-officedocument.wordprocessingml.document\")
  19.                 || mimeType.trim().equalsIgnoreCase(\"application/vnd.ms-excel\")
  20.                 || mimeType.trim().equalsIgnoreCase(\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\")
  21.                 || mimeType.trim().equalsIgnoreCase(\"application/vnd.ms-powerpoint\")
  22.                 || mimeType.trim().equalsIgnoreCase(\"application/vnd.openxmlformats-officedocument.presentationml.presentation\")) {
  23.                 Log.d(\"baron\",\"start to download \" + mimeType +\" file...\");
  24.                 return;
  25.             }
  26.             

  27.             if (!DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING.equalsIgnoreCase(mimeType)) {
  28.                 // Check to see if we are allowed to download this file. Only files
  29.                 // that can be handled by the platform can be downloaded.
  30.                 // special case DRM files, which we should always allow downloading.
  31.                 Intent intent = new Intent(Intent.ACTION_VIEW);

  32.                 // We can provide data as either content: or file: URIs,
  33.                 // so allow both. (I think it would be nice if we just did
  34.                 // everything as content: URIs)
  35.                 // Actually, right now the download manager\'s UId restrictions
  36.                 // prevent use from using content: so it\'s got to be file: or
  37.                 // nothing

  38.                 PackageManager pm = context.getPackageManager();
  39.                 intent.setDataAndType(Uri.fromParts(\"file\", \"\", null), mimeType);
  40.                 ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
  41.                 //Log.i(Constants.TAG, \"*** FILENAME QUERY \" + intent + \": \" + list);

  42.                 if (ri == null) {
  43.                     if (Constants.LOGV) {
  44.                         Log.v(Constants.TAG, \"no handler found for type \" + mimeType);
  45.                     }
  46.                     throw new GenerateSaveFileError(Downloads.Impl.STATUS_NOT_ACCEPTABLE,
  47.                             \"no handler found for this download type\");
  48.                 }
  49.             }
  50.         }
  51.     }

阅读(172) | 评论(0) | 转发(0) |
0

上一篇:ubuntu下关于git的配置和使用

下一篇:双系统在ubuntu12.04下如何修改grub的启动项

相关热门文章
  • 土豪seo人员不能不知的高级搜...
  • 司机酒驾被罚笑容灿烂 用哲学...
  • Hadoop初探之Hadoop生态圈...
  • 坑爹的KVM!Device pci-assign...
  • C++函数中那些不可以被声明为...
  • android开发---解压system.img...
  • 不用vs和cygwin!Eclipse+cdt...
  • Android自定义View的实现...
  • Android避免内存泄露:合理使...
  • 让ProgressDialog在setCancela...
  • ChinaUnix & ITPUB社区12周年...
  • ssh连接出现以下提示,求解...
  • 如何扩展MYSQL
  • 准备做一个大型门户,用户什么...
  • gbk or utf8
给主人留下些什么吧!~~
评论热议