Android 在我的应用程序中打开视频URL

Android 在我的应用程序中打开视频URL,android,android-intent,intentfilter,android-video-player,Android,Android Intent,Intentfilter,Android Video Player,关于这件事我找了很多,但什么也没找到。我的目标是用视频文件(从浏览器中选择)打开所有URL。通常,如果所有URL都以视频的文件扩展名结尾,即:www.example.com/wow.mp4,我可以使用此意向过滤器来筛选清单: <intent-filter> <action android:name="android.intent.action.VIEW" /> <data android:scheme="http"/> <data

关于这件事我找了很多,但什么也没找到。我的目标是用视频文件(从浏览器中选择)打开所有URL。通常,如果所有URL都以视频的文件扩展名结尾,即:
www.example.com/wow.mp4
,我可以使用此意向过滤器来筛选清单:

<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>

然后重定向到正确的链接。我想知道如何使用意图过滤器截取此类视频URL。MXPlayer实现此功能。

您需要调用HTTPConnection模块以获取mime类型,然后使用mime类型启动活动。 您可以参考下面的代码部分来获取URL的mime类型

你可以参考


谢谢,但这不是完整的解决方案。该代码将在我的应用程序被选择为URL后运行,无论是从接收器中还是在应用程序本身中,如果mimeType不是视频,则我的应用程序将被打开,但无法处理该意图。你知道如何通过清单来实现这一点吗?我认为这现在是一个框架主题,你应该在活动启动之前处理它,所以需要框架更改来支持这样的功能。这样想,我希望我的应用程序位于选择器对话框中,即用于播放视频。因此,我不能让用户启动我的应用程序,却发现他选择了错误的链接,而我的应用程序对此无能为力。
http://www.videoweed.es/mobile/....17da9f11345a424f02a5
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;
}