Reusing default Android image gallery?

谁说我不能喝 提交于 2019-12-06 05:35:32

问题


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:


  1. The Gallery application has no rights to access files in your application's storage directory.

  2. The Gallery application is not part of the Android operating system.

  3. 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.

  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!