问题
All the examples I've found online for displaying a gallery of images require creating a custom Adapter and doing a ton of manual work. Is there not an Intent that I can simply pass a path or filter to in order to reuse the default image gallery functionality (display thumbnails, touch to view full pic, sharing options, etc) but limit the results to my application's storage directory?
回答1:
The Gallery application has no rights to access files in your application's storage directory.
The Gallery application is not part of the Android operating system.
The Gallery application is routinely replaced by device manufacturers with their own implementations, so even if you found some screwy back-door to the regular Gallery application that enabled this, it probably would not work on many devices.
Android itself, in the open source project, has two Gallery applications (Gallery and Gallery3D), and I don't know which are necessarily on any device (if either) or which is the one that you think supplies "the default image gallery functionality".
However, those Gallery applications are open source, and so you are welcome to copy whatever code you like out of them.
回答2:
You can use this code to get the gallery started. Code for Video is
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Video"), 666);
code for Image is
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Video"), 666);
And after getting the thing form the gallery , you can do whatever you want from it Do post if you need to ask anything else Thanks
来源:https://stackoverflow.com/questions/4125616/reusing-default-android-image-gallery