0

I am trying to make a video player app. I can play video by opening my app manually. But I want to show my app as an option like below picture:
enter image description here


in short, when I click any video file in file manager, this will show my app as an option for playing that video. When user click on my app this will open a particular activity and start playing that file. How can I do this?

Abu Saeed
  • 1,020
  • 8
  • 21

4 Answers4

1

add intent filter to activity. very similar to this.

   <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="video/*" />
    </intent-filter>

also see this Forcing an app chooser

Ayush Pal
  • 154
  • 3
  • 8
  • when I add your code to an activity. it showing `Missing URL` – Abu Saeed Oct 24 '20 at 05:51
  • its working but showing red error. activity is opening but `the activity is playing the first file from the list` not that file that I click in file manager. – Abu Saeed Oct 24 '20 at 06:14
  • `` `` `` `` `` `` `` – Abu Saeed Oct 24 '20 at 14:26
  • however, how can I get the path of the video file that I clicked in file manager?? and how can I detect if my activity is opening from file manager or through app manually? – Abu Saeed Oct 25 '20 at 14:03
  • 1
    use intent to get the uri of the file in the class. – Ayush Pal Oct 25 '20 at 16:01
  • `Uri uri = getIntent().getData();` `File file = new File(uri.getPath());` `specialPath = file.getAbsolutePath();` this code is giving wrong path(tested in emulator) – Abu Saeed Oct 26 '20 at 04:30
  • 1
    https://stackoverflow.com/questions/17546101/get-real-path-for-uri-android maybe this might of some help. – Ayush Pal Oct 26 '20 at 05:51
0

Read how to achieve this in official documentation

i30mb1
  • 3,894
  • 3
  • 18
  • 34
0

You need to put an intent filter in your manifest.xml. This tells the OS which types of media/ files your app is capable of handling. When you click a video file in file manager, Android issues an implicit intent . This basically puts out a wanted ad (excuse the analogy) to other apps that the file needs to be handled. When this happens, if your app has the capability to handle this file/ media type, it will respond. From here, if there is only one capable app, it will be selected for the task. If there are multiple capable apps, all of them will be added to a list, which is then displayed to the user (the list in the image you posted above.)

Nate T
  • 727
  • 5
  • 21
  • can you give me the code of `intent-filter`. I am not getting this – Abu Saeed Oct 24 '20 at 05:52
  • It is just a bit of markup in your app's manifest.xml file. The manifest is auto-generated when you create an app in Android Studio. It holds application-scope configuration data. In other words, In other words, this is where your app stores settings that it needs to work properly. – Nate T Oct 25 '20 at 10:30
  • However, how can I get the path of the file that I clicked in file manager? – Abu Saeed Oct 25 '20 at 14:04
0

Add the below code to inside activity(that you want to open) inside manifest:

        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="video/*"/>
            <data android:scheme="content"/>
            <data android:scheme="file"/>
        </intent-filter>

use below code to your activity to get the uri of your file. I have tested the path in exoplayer.

Uri uri = getIntent().getData();
Abu Saeed
  • 1,020
  • 8
  • 21