我是这样做的:
public String getMimeType(String strUrl) throws IOException, Exception {
HttpHead httpHead = new HttpHead(strUrl);
HttpResponse response = getHttpClient().execute(httpHead);
Header[] headersArr = response.getHeaders("Content-Type");
String mimeType = headersArr[0].getValue();
return mimeType;
}
要使用它:
// check for special content
String mimeType = null;
try {
mimeType = getMimeType(urlStr).toLowerCase();
} catch (Exception e) {
}
if (mimeType != null) {
// AUDIO
if (mimeType.startsWith("audio")){
Uri uri = Uri.parse(urlStr);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(uri, "audio/*");
startActivity(intent);
return true;
} else if (mimeType.startsWith("video")){
Uri uri = Uri.parse(urlStr);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");
startActivity(intent);
return true;
}
}