5

When I get my activity chooser for my ACTION_GET_CONTENT Intent there is applications I don't want to be there, like the ones who will first create content and then pass the URI to me, like the Voice Recorder.

When you use Gmail and try to attach a file you will only see the applications/activities that picks data from your SDCard like Gallery, and in my case Astro (file manager application).

So my question is, what kind of Intent does Gmail use for their Attach?

Here is my code, something must be missing since I get applications like Voice Recorder and so on.

Intent action = new Intent(Intent.ACTION_GET_CONTENT);  
action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);  
startActivityForResult(Intent.createChooser(action, "Upload file from..."), 1);

Thank you!

Regards
Tobias

Tobias
  • 873
  • 9
  • 17

2 Answers2

0
putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath));

EDIT: possible duplicate of this, this and some more

Community
  • 1
  • 1
apps
  • 942
  • 5
  • 8
  • I don't know if I was unclear in my question or if my "Upload file from..." was confusing, it refers to "Which application do you want to use for selecting a file that will be uploaded". I don't know how to use your code, since I don't think the EXTRA_STREAM is used when running the action "GET_CONTENT". I thought EXTRA_STREAM was used when you send files to other applications. – Tobias Nov 17 '10 at 14:18
  • did you tried with http://developer.android.com/reference/android/content/IntentFilter.html – apps Nov 17 '10 at 14:21
  • It's been a missunderstanding, I don't want to send a file to another application, I want to use a file chooser that should give me files that my application will upload to a webservice. And I want that dialog that asks for a file to upload should look like the one in Gmail when you press "attach" when composing a new e-mail message. – Tobias Nov 17 '10 at 14:27
  • you can't use the gmail file picker, and if you want to start some 3rd party app you have to see which intent actions triggers it – apps Nov 17 '10 at 14:31
  • I don't want to use gmails file picker (gmails doesn't have any). Gmail must do like everyone else which is start an activity with a intent that says "I want a file". And now I want to know what their Intent looks like to get the chooser they get, I get more choices in my chooser then they do, so I need to make my Intent more narrow to exclude some of the applications that appear. – Tobias Nov 17 '10 at 15:02
  • ok, setDataType of the intent, look the IntentFilter that I gave you the link already for more information – apps Nov 17 '10 at 15:12
  • actually just setType, if you put just the mime type it should work EDIT: why do you have set it to */* , I thought that what all this is about is to exclude some apps ?? – apps Nov 17 '10 at 15:14
  • It is, but I don't know which mime to use then. Because you're not limited to any mime-type when attaching a file in gmail, they only make sure that you are attaching a file that is currently in your phone. I want to allow everything from text-files to all kinds of binary data. But I don't want Voice Recorde to be an option, since it's not an option in gmail and other similar applications to mine. – Tobias Nov 17 '10 at 15:22
  • I see now what you mean, try with setData() of content://media/external/ , if what you want is to show only stuff on the SD card – apps Nov 17 '10 at 15:24
  • yes, you are right that the mime idea is stupid, especially after that that you want to include only SD card stuff – apps Nov 17 '10 at 15:24
  • you confused me, first you said that you want to exclude the recorder, so I thought that you are after specific file types. but now I see that I didn't interpret your question right – apps Nov 17 '10 at 15:26
  • All I want is my "Application/Activity chooser" to look like Gmail's. Unfortunately setData(Uri.parse("content://media/external/")); didn't work, I get "No application can perform this action" – Tobias Nov 17 '10 at 15:39
  • If you have an Android project you can paste my code from the original question anywhere in you Activity (where it's run) and then you maybe can see my problem. – Tobias Nov 17 '10 at 15:41
  • the problem is that I don't know how to do it because I never needed a chooser so far, I am continuing to answer you just because nobody else does. try with getType (Uri url) of a contentResolver and fill the Uri with content://media/external/ , and use this as setType(). If somebody has worked on this and knows already how to do it, I will appreciate if he shares the info :) – apps Nov 17 '10 at 15:49
0

This is how it's done:

Intent intent = new Intent();
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select file"), 1);
Starwave
  • 2,352
  • 2
  • 23
  • 30