Android的 - 检测URL的MIME类型? [英] Android - Detect URL mime type?

查看:560
本文介绍了Android的 - 检测URL的MIME类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我有我从数据库访问,然后打开一个web视图来显示不同​​的URL网址。通常情况下,URL看起来是这样的:

In my Android app, I have various URLs that I access from a database and then open a WebView to display that URL. Typically the url looks something like this:

http://www.mysite.com/referral.php?id=12345

这些推介链接始终重定向/转发到另一个URL。有时所得到的网址是直接到图像。有时,为PDF。有时,它只是另一个HTML页面。

These referral links always redirect/forward to another url. Sometimes the resulting url is directly to an image. Sometimes it's to a PDF. Sometimes it's to just another HTML page.

反正,我需要能够这些不同类型的网页之间进行区分。例如,如果生成的URL链接到一个PDF文件,我想使用谷歌文档查看器伎俩来显示它。如果它只是我想简单地显示它一个普通的HTML页面,如果它是一个形象,我就准备下载图像,并以一定的方式显示它在我的应用程序。

Anyways, I need to be able to distinguish between these different types of pages. For example, if the resulting URL links to a PDF file, I want to use the Google Docs Viewer trick to display it. If it's just a plain HTML page I want to simply display it and if it's an image, I am planning on downloading the image and displaying it in my app in a certain way.

我想接近这一点的最好办法是确定最终的URL的MIME类型。你怎么做到这一点?而有没有更好的方式来完成我想要的吗?

I figure the best way to approach this is to determine the mime type of the resulting url. How do you do this? And is there a better way to accomplish what I want?

推荐答案

我觉得内容类型的HTTP标头应该做的伎俩:

I think content type http header should do the trick:

内容类型

这篇关于Android的 - 检测URL的MIME类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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