若你通过DownloadManager来来download一些比如epub等这样格式的file,你会遇到no handler found for type application/epub+zip这样的error message.这是因为DownloadManger只允许download能处理的file而那些file没有对应的Activity处理的就会选择不download.具体的代码:
package com.android.providers.downloads;
Helpers.java
/**
* Creates a filename (where the file should be saved) from a uri.
*/
public static DownloadFileInfo generateSaveFile(
Context context,
String url,
String hint,
String contentDisposition,
String contentLocation,
String mimeType,
int destination,
int contentLength) throws FileNotFoundException {
/*
* Don't download files that we won't be able to handle
*/
if (destination == Downloads.DESTINATION_EXTERNAL
|| destination == Downloads.DESTINATION_CACHE_PARTITION_PURGEABLE) {
if (mimeType == null) {
if (Config.LOGD) {
Log.d(Constants.TAG, "external download with no mime type not allowed");
}
return new DownloadFileInfo(null, null, Downloads.STATUS_NOT_ACCEPTABLE);
}
if (!DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING.equalsIgnoreCase(mimeType)) {
// Check to see if we are allowed to download this file. Only files
// that can be handled by the platform can be downloaded.
// special case DRM files, which we should always allow downloading.
Intent intent = new Intent(Intent.ACTION_VIEW);
// We can provide data as either content: or file: URIs,
// so allow both. (I think it would be nice if we just did
// everything as content: URIs)
// Actually, right now the download manager's UId restrictions
// prevent use from using content: so it's got to be file: or
// nothing
PackageManager pm = context.getPackageManager();
intent.setDataAndType(Uri.fromParts("file", "", null), mimeType);
ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
//Log.i(Constants.TAG, "*** FILENAME QUERY " + intent + ": " + list);
if (ri == null) {
if (Config.LOGD) {
Log.d(Constants.TAG, "no handler found for type " + mimeType);
}
return new DownloadFileInfo(null, null, Downloads.STATUS_NOT_ACCEPTABLE);
}
}
}
String filename = chooseFilename(
url, hint, contentDisposition, contentLocation, destination);
// Split filename between base and extension
// Add an extension if filename does not have one
String extension = null;
int dotIndex = filename.indexOf('.');
if (dotIndex < 0) {
extension = chooseExtensionFromMimeType(mimeType, true);
} else {
extension = chooseExtensionFromFilename(
mimeType, destination, filename, dotIndex);
filename = filename.substring(0, dotIndex);
}
中的
PackageManager pm = context.getPackageManager();
intent.setDataAndType(Uri.fromParts("file", "", null), mimeType);
ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
//Log.i(Constants.TAG, "*** FILENAME QUERY " + intent + ": " + list);
if (ri == null) {
if (Config.LOGD) {
Log.d(Constants.TAG, "no handler found for type " + mimeType);
}
return new DownloadFileInfo(null, null, Downloads.STATUS_NOT_ACCEPTABLE);
就是对这个的处理。
若你要使它能download你想要download的任何类型的file,你可以将上面这段代码去掉。也就是对DownloadManager进行修改。或许你不想修改DownlodManager进行修改,那么你可以增加一个Activity来处理你的特定类型的file。这样DownloadManager就能找到这个Activtiy,就能下载了。比如:
<activity android:name=".ViewDownload" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/epub+zip" />
</intent-filter>
</activity>
这样就能下载epub这样file了。
具体的你可以参考这篇文章:
http://a.77mi.com/Thread/view/id-14016
分享到:
相关推荐
主要介绍了解决ubuntu vps安装docker时报错:Cannot connect to the Docker daemon at unix:///var/run/docker.sock.问题的相关资料,文中介绍非常详细,需要的朋友可以参考借鉴,下面来一起看看吧。
[popUpView addBtnWithTitle:@"取消" type:LQPopUpBtnStyleCancel handler:^{ // do something... }]; [popUpView addBtnWithTitle:@"确定" type:LQPopUpBtnStyleDefault handler:^{ // do something......
解决在springboot+mybatis+postgresql时,数据库字段类型为json时,如何与mybatis进行映射
java sql笔试题示例 Hive UDF 项目 介绍 该项目只是一个示例,包含多个 (UDF),用于 Apache Spark。 它旨在演示如何在 Scala 或 Java 中构建 Hive UDF 并在 . 为什么要使用 Hive UDF? Hive UDF ...D
// TODO: Add your control notification handler code here m_Display = m_Display+_T("1"); UpdateData(FALSE); } void CCalcDlg::OnButtontwo() { // TODO: Add your control notification handler code ...
// TODO: Add your command handler code here //--资源访问 CString s; s.Format("res://%s.exe/%d", ::AfxGetAppName(), IDR_HTML1); Navigate2(s); } 2、innerHTML操作内存中的HTML void CInerHTMLView::...
WKWebView Swift3.0 一款IOS8以后的web加载神器 ... 别说了!!!!...WKWebView 支持POST请求 加载本地页面 直接加载网页 JS交互 集成支付宝/微信URL支付功能 仿微信返回按钮 ...感谢大家的支持 OC版本将不再持续更新 ...
// TODO: Add your control notification handler code here ncheck=((CButton *)GetDlgItem(IDC_RADIO1))->GetCheck(); if(ncheck) { //send(); MessageBox("已正确选择机场!"); } } //战区 void ...
SkDCOMbridge : COM/DCOM Handler ObjectCOM/DCOM处理对象
这是Pro Android学习系列中Android Service部分的例子源代码。相关学习笔记见:http://blog.csdn.net/flowingflying/article/details/6212512
NULL 博文链接:https://malixxx.iteye.com/blog/560674
// Set the small icon for this dialog SetIcon(AfxGetApp()->LoadIcon(IDI_ICOBTN_SHELL), FALSE); CenterWindow(); // TODO: Add extra initialization here TCHAR szIp[100]; DWORD dwPort = m_hServer....
资源使用说明:http://blog.csdn.net/qq5132834/article/details/70053723
}, handler: function(msg) {//called when a message arrived ('this' is scope - see below) this.received = msg.body;//"this" is "someObject" }, scope: someObject}); 主要特点: 1. 可定制以及回调功能2. ...
handler = function ( event , context ) { var result = { } execute ( result , { shell : "echo `ls /tmp/`" , // logs output of /tmp/ dir on your lambda machine logOutput : true } ) . then ( function (
微信小程序小技巧系列:微信小程序操作中遇到的问题解决技巧。 (此图片来源于网络,如有侵权,请联系删除! ) 微信小程序小技巧系列《一》幻灯片,tab导航切换: ...
这是一个关于英语advertisement的PPT,下载有利于大家制作PPT。
Image Gallery with Lightbox effect and slideshow functionality for jQuery UI. 示例代码: $('a[rel=gallery]').imagegallery({ open: function (event, ui) {/* called on dialogopen */}, title: 'Image...
private Handler h=null; //线程共用一个handler private Handler h1=null; //线程共用一个handler ImageView iDisp=null;//要显示图片的控件 Drawable dRabbit=null;//兔子图片 Drawable dWolf=...
// when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here return TRUE; //...