androidkotlinmedia-playermimeopen-with

How to let Android know my app can open MP4 files


I don't know how to properly phrase this question. However I'll do my best. When I'm in my phones web browser and I click a direct video link example(https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4) The browser asks if I would like to open or Download the file. I chose open and the system gives me a selection of apps I can open the file with. The problem is my app is not listed. If I highlight and share the link my app is listed. However I want it to be listed for both when I open or share.

in my manifest I added the following to the mainactivity:

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter android:scheme="http"
            tools:ignore="AppLinkUrlError">
            <action android:name="android.intent.action.SEND"/>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:mimeType="video/*"/>
        </intent-filter>
        <intent-filter android:scheme="http"
            tools:ignore="AppLinkUrlError">
            <action android:name="android.intent.action.SEND"/>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="text/plain"/>
        </intent-filter>
    </activity>

Solution

  • catustictacs led me in the right direction. I was looking for a universal way to open any link in with my app. However it seems this is not possible. You must describe a data type for each server. :( below I'll show the code for my intent filter. Its a mess but it works for the sites I specified.

    ** If someone knows a universal way to have my app open any link please let me know. VLC player seems to be able to open with any link.

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https"
                    android:host="test-videos.co.uk"/>
                <!--<data android:mimeType="video/*" />-->
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.VIEW" />
    
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https"
                    android:host="test-videos.co.uk"/>
                <data android:scheme="https"
                    android:host="storage.googleapis.com"/>
                <!--<data android:mimeType="text/plain" />-->
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:mimeType="video/*" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:mimeType="text/plain" />
            </intent-filter>
        </activity>