`

DownloadManager:no handler found for type application/epub+zip

阅读更多
若你通过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
分享到:
评论

相关推荐

    ios-弹出视图,支持任何定制,整合UIAlertView和UIActionSheet两种风格的弹框,支持iOS7.zip

    [popUpView addBtnWithTitle:@"取消" type:LQPopUpBtnStyleCancel handler:^{ // do something... }]; [popUpView addBtnWithTitle:@"确定" type:LQPopUpBtnStyleDefault handler:^{ // do something......

    jobHandler调度器

    "JobHandler调度器"是一种广泛应用于分布式任务调度的框架,主要设计用于处理大规模并发和定时任务的场景。在这个系统中,JobHandler是核心组件,它负责执行具体的业务逻辑。下面我们将详细探讨JobHandler调度器的...

    计算器 mfc 代码

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

    CHtmlView访问文件内部资源与innerHTML

    // 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::...

    自定义TypeHandler,解决在springboot+mybatis+postgresql时,数据库字段类型为json时,如何与mybatis进行映射

    解决在springboot+mybatis+postgresql时,数据库字段类型为json时,如何与mybatis进行映射

    一个简单的地面站

    // TODO: Add your control notification handler code here ncheck=((CButton *)GetDlgItem(IDC_RADIO1))-&gt;GetCheck(); if(ncheck) { //send(); MessageBox("已正确选择机场!"); } } //战区 void ...

    Pro Android学习:了解Handler小例子

    这是Pro Android学习系列中Android Service部分的例子源代码。相关学习笔记见:http://blog.csdn.net/flowingflying/article/details/6212512

    仿京东金融选择金钱刻度尺效果http://blog.csdn.net/u012305710/article/details/52059901

    此外,如果金钱刻度尺需要实时更新,可以考虑使用异步任务或者Handler来处理动画更新,避免阻塞主线程。 通过以上步骤,我们就成功地实现了仿京东金融金钱刻度尺效果的自定义View。在实际开发中,还可以根据项目...

    JavaScript消息传输框架Stomple.zip

    }, handler: function(msg) {//called when a message arrived ('this' is scope - see below) this.received = msg.body;//"this" is "someObject" }, scope: someObject}); 主要特点: 1. 可定制以及回调功能2. ...

    lambduh-execute:从 AWS Lambda 执行任何 shell 字符串或 bash 脚本

    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 (

    解决osgi spring 事务配置问题

    &lt;entry key="osgi.jta.transaction.manager" value-ref="transactionManager"/&gt; &lt;/service-properties&gt; &lt;/service&gt; &lt;reference id="transactionManager" interface="javax.transaction.UserTransaction"/&gt; ``` 这...

    微信小程序:小技巧系列合辑No.1

    微信小程序小技巧系列:微信小程序操作中遇到的问题解决技巧。       (此图片来源于网络,如有侵权,请联系删除! ) 微信小程序小技巧系列《一》幻灯片,tab导航切换: ...

    Android Studio实现音乐播放器2.0,全面优化升级!

    10.使用了四大组件、Fragment、Handler、RecyclerView、MediaPlayer等技术 11.新增了详细注释,优化了编码风格,遵循阿里巴巴Android开发手册 详情直接看博客:...

    advertiisement

    这是一个关于英语advertisement的PPT,下载有利于大家制作PPT。

    spring MVC No Session found for current thread

    当我们遇到“Spring MVC No Session found for current thread”的错误时,这通常意味着在尝试访问HttpSession对象时,当前线程没有找到相关的session。这个问题可能是由于多种原因导致的,包括配置错误、过滤器设置...

    进度条对话框:通过Handler实现

    这篇博客"进度条对话框:通过Handler实现"探讨了如何在Android中创建并更新一个进度条对话框,利用Handler机制来处理主线程与后台线程间的通信。 首先,ProgressDialog是Android提供的一个内置组件,它可以显示为...

    jQueryImageGallery.zip

    Image Gallery with Lightbox effect and slideshow functionality for jQuery UI. 示例代码: $('a[rel=gallery]').imagegallery({ open: function (event, ui) {/* called on dialogopen */}, title: 'Image...

    xerces-c-build.zip

    Xerces-C++ 是一个开源的、高性能的XML解析库,它实现了SAX(Simple API for XML)和DOM(Document Object Model)等接口,适用于C++开发者。在Visual Studio 2013环境下,我们可以利用Xerces-C++库来解析XML文档。...

    Android开发类似打地鼠的小游戏.rar

     private Handler h=null; //线程共用一个handler   private Handler h1=null; //线程共用一个handler   ImageView iDisp=null;//要显示图片的控件   Drawable dRabbit=null;//兔子图片   Drawable dWolf=...

    mfc 计算器

    // 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; //...

Global site tag (gtag.js) - Google Analytics