How do I activate an activity in the Select File dialog box?

Example: when you click the button to upload an image, you get a file selection dialog. Then you can select the application you want to select. How can I make my application in this dialog box?

+6
source share
3 answers

Add the following intent filters to your activity where you want the selection to be made:

<intent-filter > <action android:name="android.intent.action.PICK" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="file" /> </intent-filter> <intent-filter > <action android:name="android.intent.action.GET_CONTENT" /> <category android:name="android.intent.category.OPENABLE" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="*/*" /> </intent-filter> 

The first handles the Action Pick, and the second handles Get Content.

You can change your mimeType to limit your selection a bit. The one I provided will put your application in a selector for each type of file.

+1
source

You need to add an Intent filter to your manifest file in the action that you want to handle at boot time. For example: I have an Activity that handles the import of images, this is what I wrote.

 activity android:name="com.ImportTheme"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="*" android:scheme="file" android:mimeType="image/*" /> </intent-filter> </activity> 

As you can see, you need to add a mime type suitable for what you are looking for. In my example, I want only pictures - png, jpg, etc.

Go to the following link, you have a list of mime types.

+2
source

A simple and complete code example (less than 50 lines) for an application that android will present to the user along with a list of compatible application menus (polarizer, browser, etc.) when opening a TXT file.

disclaimer: in case the user has not previously defined the default application

Note: TXT can be changed for other extensions, always paying attention to mime types.

0
source

All Articles