Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make activity appear in "Choose file" dialog?

Example: when you click a button to upload an image, you get the dialog to choose a file. Then you can select an app you want to choose it. How can I make my app appear in that dialog?

like image 638
Rotary Heart Avatar asked Feb 18 '13 22:02

Rotary Heart


2 Answers

You need to add an Intent filter to your manifest file in the activity you want to handle the upload. For example: I have an Activity that handles image import, 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 mime type that suitable to what you looking for, at my example, I want only pictures - png, jpg etc.

Check in the next link, you have a list of mime types.

like image 75
Ofir A. Avatar answered Nov 14 '22 12:11

Ofir A.


Add the following intent filters to your Activity where you want the picking to take place:

        <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 one handles an Action Pick, and the second one Get Content.

You may want to change your mimeType to restrict selection a little. The one I provided will put your app in the selector for every type of file.

like image 44
Raghav Sood Avatar answered Nov 14 '22 13:11

Raghav Sood