我对此进行了大量搜索,但未能找到任何内容。我的目标是使用视频文件(从浏览器中选择)打开所有URL。通常情况下,如果所有网址都以视频的文件扩展名结尾.E:www.example.com/wow.mp4
我可以使用此Intent过滤我的清单:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http"/>
<data android:scheme="https"/>
<data android:mimeType="video/*">
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
但在所有地方都不是这样,有些网址的起点如下:
http://www.videoweed.es/mobile/....17da9f11345a424f02a5
然后重定向到正确的链接。我想知道如何使用Intent Filter拦截视频的这些URL。 MXPlayer实现了这一功能。
答案 0 :(得分:1)
您需要调用HTTPConnection模块来获取mime类型,然后使用mime类型启动活动。 您可以参考下面的代码部分来获取mime类型的URL。
您可以参考Android - Detect URL mime type
import java.net.URL;
import java.net.URLConnection;
public static String getMimeType(String url)
{
String mimeType = null;
// this is to handle call from main thread
StrictMode.ThreadPolicy prviousThreadPolicy = StrictMode.getThreadPolicy();
// temporary allow network access main thread
// in order to get mime type from content-type
StrictMode.ThreadPolicy permitAllPolicy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(permitAllPolicy);
try
{
URLConnection connection = new URL(url).openConnection();
connection.setConnectTimeout(150);
connection.setReadTimeout(150);
mimeType = connection.getContentType();
Log.i("", "mimeType from content-type "+ mimeType);
}
catch (Exception ignored)
{
}
finally
{
// restore main thread's default network access policy
StrictMode.setThreadPolicy(prviousThreadPolicy);
}
if(mimeType == null)
{
// Our B plan: guessing from from url
try
{
mimeType = URLConnection.guessContentTypeFromName(url);
}
catch (Exception ignored)
{
}
Log.i("", "mimeType guessed from url "+ mimeType);
}
return mimeType;
}