how to open app from file manager and play video directly? - android

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

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

Read how to achieve this in official documentation

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

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();

Related

How to make our app visible in the "Open with" in android?

I'm working on an android app which could view or edit pdf files.
My app shows up in the "Open file using..." screens.
here is the screenshot
But when I click a pdf file from google files file manager app, it shows "Open with" screen and my app is not there. here is the screenshot
This is my intent filter in manifest.xml :
<intent-filter android:label="View or edit your pdf files">
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT"/>
<data android:scheme="content" />
<data android:mimeType="application/pdf" />
</intent-filter>
How can I make my app visible in the "Open with" screen like Drive Pdf Viewer and WPS Office in the second screenshot ?
I have applied your code in my app and everything worked fine. Don't know what exactly is happening here, but in your case you can define intent filters with lots of actions and data type (category is not necessary in my opinion) to see that if your app can be a candidate to handle the intent. Then in the activity receiving the intent, in the onNewIntent() method, you check all the properties of the incoming intent to see what's is missing in your current solution. All the possible intent's actions can be found in the document (you dont need to define all of them, just add the most popular ones and see the result)
https://developer.android.com/reference/android/content/Intent

Android open video with custom app

one of my project I was develop video player app for android.
when we browse video using android device file explorer and select it then usually
popup a window and show the possible video player apps.
as showing red area in this image
In my case I wanna show my video player app just like this red area apps showing. how can I do this. Is there any way to do this in programmatically in android.
you have to mention intent filter for your activity that plays video,so that it is visible for other apps.
you can read more about that here
Allowing Other Apps to Start Your Activity
example:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/*" />
<data android:mimeType="application/sdp" />
</intent-filter>
you can also see the answer given by #Michell Bak

Handling Media Files in Android by installed apps

I have an app which records Audio and video. Then there is a list in the app which displays these recorded files. When user clicks on one of this file, I would like to display an option of apps that user can choose to play this clicked file. An example of it is shown below.
All the examples I have looked on internet is of using a media player which I am already doing but I would like the pause, stop etc function to be handled by an already available app in the users device.
Is this possible to do? If so how?
I guess your Activity which handles Audio and Video should have this in AndroidManifest.
The below intent-filer is for Audio files, similarly you can add for Video files for the same Activity.
<activity ...>
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="audio/*"/>
</intent-filter>
</activity>
EDIT:
For your Activity
Suppose you show a list of audio files and user is suppose to click one. So when the user clicks some item. You just need to set the result.
Ex.
setResult(RESULT_OK, new Intent().setData(YOUR_URI));
The 2nd param is just the data which we need to pass to the calling Application basically we pass the URI of the data.
EDIT 2: The RESULT_OK is inherited variable of Activity. You don't need to define it.
I hope it helps you.
I found the answer by readin up on the internet.
First prepare the file location and then open an intent with the data at this location
Uri fileURi = Uri.parse(tempFileURi); //i.e. /storage/emulated/0/Android/data/com.sahilsaid.appname/files/Music/Recording200.3gp
File file = new File(fileURi.toString());
if (file.exists()) {
Uri finalFileUri = Uri.fromFile(file);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(finalFileUri, URLConnection.guessContentTypeFromName(finalFileUri.toString()));
startActivity(intent);
}
You will also need to modify your AndroidManifest.xml file and add intent-filter as suggested above by #Aky
<activity
android:name=".exampleActivity"
android:label="#string/title_activity_example">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="audio/*"/>
</intent-filter>
</activity>
For more info visit this article:
https://software.intel.com/en-us/blogs/2014/03/20/video-playing-with-android-media-player

Android: register app as file picker

I would like to register my app as Android app system for the selection of files (like Dropbox).
Basically when the user is, for example, on a web page in the browser and press the html button "Browse ..." the operating system should show the available options (system gallery, GDrive, Dropbox, etc.) and also my app. Once you select the file (in this case CSV) should be returned to the field in the file browser and and processed as a normal file.
how can I register the app as file picker and how can I return the file to the app caller?
Thanks
You need in your Manifest.xml define intent filter for your Activity like this:
<intent-filter android:label="#string/pick_file">
<action android:name="android.intent.action.GET_CONTENT" />
<data android:mimeType="*/*"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
</intent-filter>
Where's "mime-type" is your file extension, that you want to choose. You can read more about it here.

Reading a custom file launched using Box

We have developed an Android app which is used for rendering files of our custom file type (.vds). I am able to launch my app for all the files (.vds file) which are stored on local storage, but if the files is stored on Box and I try to access them using the Box Android App then I am facing issues. I have created the following intent filter:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.vds" />
The problem is that in the corresponding activity I am able to get the intent, but if I try to read the URI (as our rendering logic is based upon file location) it gives me a path which doesn't exists on the SD card. What happens if we try to open a file using Box Android Native App? Where is the file downloaded and how should the downloaded file be accessed?
This may solve ur problem. Add the bellow intent filter.
<activity android:name=".Activity"
android:screenOrientation="portrait"
android:label="#string/app_name">
<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.VIEW"/>
<action android:name="android.intent.action.EDIT"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:pathPattern="*.snowdragon"/>
<data android:mimeType="text/snowdragon"/>
</intent-filter>
</activity>
As noted above I've run into the same problem. While I've not found what I would consider to be The Right Solution(TM) I do have a couple of things to add that might be useful to others:
First, I've discovered that if I download the file in Box (not the same as mark for offline) then clicking the item in either the download result dialog or in the subsequent notification that appears at the bottom of the app works. Once you've dismissed that notification however, there does not seem to be a way to get back to the downloaded file from within Box.
Second, and let me qualify this by saying that I've not looked very closely at it yet but I think one could use the filename info in the intents for non-existent files to retrieve the file via the Box API, either directly from the cloud or possibly via API call to retrieve offline items. I'm wondering if this is actually what Box is trying to get us to do with these bogus file paths, considering that they are so blatantly bogus:
12-04 10:09:29.318: INFO/ActivityManager(607): START u0
{act=android.intent.action.VIEW dat=file:///non_existent_dummy_folder/foo.abcdef typ=application/abcdef cmp=com.foo.bar/.app.FooViewer}

Categories

Resources