6

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?

imz -- Ivan Zakharyaschev
  • 4,921
  • 6
  • 53
  • 104
Rotary Heart
  • 1,899
  • 3
  • 29
  • 44
  • can you add your code for creating this choose file dialog ? – Shoshi Feb 18 '13 at 22:56
  • @Shoshi I didn't create it. I just clicked an upload button in a web page. – Rotary Heart Feb 18 '13 at 22:59
  • 1
    You need to declare the appropriate [IntentFilters](https://developer.android.com/reference/android/content/IntentFilter.html) for your Activity in your manifest, please read: [Android file chooser](http://stackoverflow.com/q/7856959/1267661) – Sam Feb 18 '13 at 23:00

3 Answers3

2

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.

Ofir A.
  • 3,112
  • 11
  • 57
  • 83
1

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.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • I think he should restrict the mimeType somewhat. In my app, when I put in */*, it started showing up everywhere. – DigCamara Feb 18 '13 at 23:04
  • @DigCamara The current mime type basically says "My app can help you pick PDFs, images, videos, text files or basically anything in existence." He can change it to whatever specific type of file he wants if he only supports one filetype. – Raghav Sood Feb 18 '13 at 23:04
  • --we're basically in agreement. I just thought it needed to be written out explicitly so he wouldn't fall into that trap. – DigCamara Feb 18 '13 at 23:07
  • @DigCamara Yep. I agree with you fully :) I've edited my answer to include a note on that. Thank you for pointing it out! – Raghav Sood Feb 18 '13 at 23:08
  • Hey one question, what name should I put in the return method? – Rotary Heart Mar 21 '13 at 23:23
  • @rotary it's usually "data", I think. I'm not sure though, so you might want to check the official documentation – Raghav Sood Mar 22 '13 at 00:00
0

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.

Community
  • 1
  • 1
tony gil
  • 9,424
  • 6
  • 76
  • 100