如何显示文件的preVIEW,并在其Android应用程序打开文件? [英] How to show preview of file and open up file in its application in Android?

查看:334
本文介绍了如何显示文件的preVIEW,并在其Android应用程序打开文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选项,在应用程序中的附加文件。我这个,我需要向用户展示一个preVIEW或特定项目类型图标。与扩展名为.txt,.doc和.PDF,.JPEG,.MP4图标需要有自己特定的图标或如果可能的话一个好的preVIEW缩略图图标。而当用户要查看它,他将点击图标或preVIEW。我需要启动的意图来查看文件。

I have a option to attach files within a application. I this I need to show users a preview or a icon for specific item type. Icons with extension .txt, .doc, .pdf, .jpeg, .mp4 need to have its own specific icons or if possible a good preview thumbnail icon. And when the user wants to view it he would be clicking on the icon or preview. I need to start a intent to view the file.

我的意思是一个PDF应以PDF阅读器打开,或者一个txt文档或应打开文本阅读器,一个MP3或MP4应该在音频或视频播放器..和重要组成部分打通我希望他们COM回到我的应用程序时,他们做了一回出来的查看应用程序的。

I mean a pdf should open up in a pdf reader, or a txt or doc should open in text reader, a mp3 or mp4 should open up in a audio or video player.. and the important part I want them to com back to my application when they do a back out of the view application.

在我心中唯一的想法就是通过文件名来搜索和手动拆分出来的延伸和做字符串比较来检查对常量字符串值,如.MP3或.MP4等,这是不一个好主意,因为有很多扩展的图像,音频和视频的类型。请让我知道,如果有这样做的任何直接的方式。谢谢你的帮助。

The only idea in my mind is to search through the file name and manually split out the extension and do a string compare to check it against the constant string values like ".mp3" or ".mp4" etc. This is not a good idea as there are lot of extensions for image, audio and video type. Please let me know if there is any straight forward way to do this. Thank you for your help.

推荐答案

您也可以读取文件的MIME类型和这样做的。可能不仅仅是阅读延伸虽然都可能会工作更加精确。

You could also read the mime type of the file and do it that way. Might be more accurate than just reading the extension although both would probably work.

http://developer.android.com/reference/android/webkit/ MimeTypeMap.html

guessContentTypeFromStream(InputStream的)

您就可以有一个参考各个图标可绘制的一个数组列表。

You can then have an array list of drawables that refer to each icon.

这篇关于如何显示文件的preVIEW,并在其Android应用程序打开文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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