Search code examples
androidmime-typesandroid-implicit-intent

Android implicit intent does not show correct list of apps for playing mp4 file


I have a foreground service that is supposed to launch an implicit intent to play a mp4 file. The intent goes like this:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(media_uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
}

The variable media_uri contains the Uri of the mp4 file. The intent filter is this:

<service
    android:name=".MahalayaService"
    android:exported="false"
    android:taskAffinity=""
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="application/mp4" />
    </intent-filter>
</service>

The intent launches a list of apps, but none of them can play the mp4 file:

enter image description here

Note that I have some programs installed that can play the mp4 file. When I click on the mp4 file from the file browser, I see this:

enter image description here

Where am I going wrong? Why does the implicit intent not launch the correct set of apps for playing the mp4 file? Have I set a wrong MIME type?


Solution

  • Found the answer! Yes, I set a wrong MIME type.

    I modified the intent to intent.setDataAndType(media_uri, "video/*"); and modified the intent-filter to <data android:mimeType="video/mp4" />. This solved the problem.