简体   繁体   中英

Create an Attach File dialog in Android

After reading some posts like this one:

Choose File Dialog

It appears that Android OS might not have a built-in dialog for "select a file" like we have on Windows OS. Is that correct?

If not, I need to create one for attaching files to an email (I'm creating an email client). There are enough samples for creating a directory list and showing it in a listview. What I can't find is a way to know what folders/paths I should look in, or at least start with? For example, the built-in "Messaging" app on the emulator I am testing with brings up a list to start with that has options like "Audio, Images, Videos, Slideshows", and then when I select one of those options it appears to be showing me all of those types of files, maybe from anywhere on the device, in one big list.

Is there some "accepted" or "common" way of doing this? I don't want my app to be too different from others that users might be used to.

Also.. it seems like Android doesn't generally have usefull file names on most of these files, most are just numbers, so I guess I'll have to display thumbnails --- seems like a lot of work, for a pretty common/basic task I would think would be part of the OS.

I think this is what GMail uses:

        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent,"Select File"), AttachFileRequestCode);

So I decided that will be good enough for me. For most people I think they will only get the "Gallery" app with this method, but at least "advanced" users have an option to install a 3rd party file explorer if they want to be able to select other files. I tried using / for the mime-type, but then the list included contacts and some other items that didn't work well at all, so I left it image/* and it appears most file explorers will ignore that and let the user select any file type they want anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM