无法在MARSHAMALLOW文件选择器中选择pdf,doc,ppt之类的文件 [英] unable to pick files like pdf,doc,ppt in MARSHAMALLOW file chooser

查看:115
本文介绍了无法在MARSHAMALLOW文件选择器中选择pdf,doc,ppt之类的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用android应用程序将pdf,ppt,doc等文件上传到服务器,但是在棉花糖中,当文件选择器打开并且我浏览我的SD卡或内部存储设备时,有两个问题:
1.它显示所有我无法选择但我使用意图类型作为application/pdf的文件,例如图像,视频和文档等; appkication/ppt等,因此应该让我选择那些文件.
2.其次,当我使用外部文件管理器(如ES文件浏览器等)时,它会显示所有文件,如图像,视频,文档,apk,这一次,我可以选择任何类型的文件
这是我的文件选择器代码

I am uploading files like pdf,ppt,doc etc to server using from my android app but in marshmallow when file chooser opens and i browse my Sdcard or internal storage there are two problmes :
1. it shows all files like images,videos and documents etc which i cannot pick but i used intent type as application/pdf; appkication/ppt etc.,so it should let me pick those files.
2. secondly when i use external file manager like ES file explorer etc it then show all files like images,videos,documents,apks and this time it lets me choose any type of file
here is my code for file chooser

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("application/pdf;application/docx;application/xlsx;application/pptx;application/pptx;application/txt");
            startActivityForResult(intent, PICK_FILE_REQUEST);  

我正在使用棉花糖,我认为它仅在棉花糖中发生,因为我没有其他设备可以测试此代码,因此请在此处帮助我

我这样尝试过

intent.setType("application/pdf|application/docx|application/xlsx|application/pptx|application/txt");

但是它没有让我选择任何文件,但是如果我仅使用一种MIME类型(例如pdf或docx),那么它可以工作,让我选择pdf或docx,然后我在互联网上进行搜索,发现这种方式可以使用多种MIME类型使用|代替 ;对于大多数用户来说,它工作正常,但对我而言却不是.

but it didnt let me chose any file but if i use only one MIME type like pdf or docx then it works and let me pick pdf or docx and i searched across internet and found this way to use multiple MIME type that is by using | instead of ; and for most of users it works fine but dont for me.

推荐答案

setType()不采用以竖线分隔的类型列表或以分号分隔的类型的列表.它采用单个 MIME类型.

setType() does not take a pipe-delimited list of types, or a semicolon-delimited list of types. It takes a single MIME type.

在API级别19+设备上,欢迎您添加EXTRA_MIME_TYPES 到您的Intent(其他MIME类型的String[]).从理论上讲,ACTION_GET_CONTENT实现应该兑现这一点.实际上,我希望很少有人会这样做. ACTION_OPEN_DOCUMENT可能更可靠,因为Android本身可以实现,而ACTION_GET_CONTENT则依赖于应用开发者的实现.

On API Level 19+ devices, you are welcome to add EXTRA_MIME_TYPES to your Intent (a String[] of additional MIME types). In theory, ACTION_GET_CONTENT implementations should honor this. In practice, I expect that few would. ACTION_OPEN_DOCUMENT may be more reliable, in that Android implements that itself, whereas ACTION_GET_CONTENT relies upon app developer implementations.

由于Intent用于ACTION_GET_CONTENT(即,您正在请求内容),因此可以使用application/*,尽管这样会得到一些您不支持的文件类型.

Since your Intent is for ACTION_GET_CONTENT (i.e., you are requesting content), you can use application/*, though this will get you some file types that you cannot support.

否则,一次只要求一种MIME类型.

Otherwise, only ask for one MIME type at a time.

这篇关于无法在MARSHAMALLOW文件选择器中选择pdf,doc,ppt之类的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆