Chinaunix首页 | 论坛 | 博客
  • 博客访问: 514712
  • 博文数量: 92
  • 博客积分: 3146
  • 博客等级: 中校
  • 技术积分: 2314
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-27 10:20
文章分类

全部博文(92)

文章存档

2014年(3)

2013年(17)

2012年(16)

2011年(22)

2010年(34)

分类: Android平台

2013-05-08 14:22:03


点击(此处)折叠或打开

  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.     }

阅读(1371) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~