Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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.

simple and complete example code (less than 50 lines) for app that android will present to the user along with menu list of compatible apps (polaris, browser, etc) when opening a TXT file.

disclaimer: in case user hasnt previously determined a default app

note: TXT may be changed for other extensions, always paying attention to mime types.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top