如何为Android实现自定义设备照片库?
我正在开发 Android 应用程序,它将包含基本的图片库功能。我已经成功构建了从应用程序后端 API 获取照片列表并在活动布局内的 android gridview 中渲染它们的活动。
这是目前的样子:
但是,我很难为由相机拍摄并存储在设备上的用户设备照片构建相同的图库体验。我考虑的两个解决方案是:
- 建立我自己的图片库。
- 使用意图启动默认的 Android 图片库。
解决方案 1:我相信第一个解决方案将花费我太多的时间来开发。我从本教程开始,但是当我实施它时,我发现它运行得太慢了。然后我看一下 android 相机 source code 来寻找解决方案,但我再次发现,检查代码并从头开始构建自己的画廊将花费我太多时间。我还相信,Android 操作系统的理念不是重写已经存在的功能,而是使用 Intent 来启动可以处理您需要的操作的活动。这导致我想到了第二个解决方案。
解决方案 2: 我尝试使用 Intent 调用默认的 Android 图库,以便浏览用户的设备照片,但很快我又陷入困境。这次的问题是,一旦用户点击照片,图库就会退出并返回到最初启动它的活动,而我期望(并且我想要)开始大图像预览。我看到其他人也有这个问题 如何通过意图打开画廊而没有结果。 因为我没有找到解决这个问题的方法,所以我决定退出。
我的问题是如何克服这些问题并建立类似于我已经拥有的网络照片图库。 如果有人能给我参考,我将非常感激。
I'm working on android application that will have basic image gallery functionality included. I've managed to build activity that fetches list of photos from my application backend API and render them in android gridview within activity layout.
This is how it looks like at the moment:
However I'm having difficulties to build same gallery experience for user's device photos that were taken by camera and stored on device. Two solutions I considered were:
- Building my own image gallery.
- Starting default android image gallery using intent.
Solution 1: I belive that first solution will take me too much time to developed. I started with this tutorial but as soon I implemented it I found out that it is running too slow. Then I take a look at android camera source code to find solution but again I found that it will take me too much time to review the code and to build my own gallery from scratch. I also believe that it is not in Android OS philosophy to rewrite functionalities that already exists but to use Intents to start activities that can handle actions you need. This lead me to second solution.
Solution 2: I tried calling default android gallery using intent in order to browse user's device photos by soon I was stuck again. Problem this time was that as soon as user tap on photo, gallery exits and returns to activity that originaly started it, and I expected (and I want) to start large image preview instead. I saw that others had this problem too how to open gallery via intent without result.
Because I didn't find the fix for this I decided to quit.
My question is how can I overcome these problems and build gallery that is similar to one I already have for web photos.
If anyone could give me reference I would be most thankful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题已经很老了,但是,由于它有很多观点和很多赞成票,所以最好给出一个答案。
因此,首先教程进行了一些改进,您可以为您的 #1 选项找到一些很酷的东西:
对于您的#2选项,我不认为有任何不返回原始活动的想法,因为您仍然无法控制通过系统发送的意图的结果。
但是还有另一个您没有提到的解决方案:有一些非常酷的库,您可以自定义它们以获得您想要的内容:
this question is pretty old but, as it has a lot of views and quite a lot of upvotes, it could be good to bring an answer to it.
So, first the tutorials evolved a bit and you can find some cool stuff for your #1 option:
For your #2 option, I do not see any idea to not to return to the original activity because you still do not have control over the result of the intent you send through the system.
But there are another solution that you didn't mention: there are librairies which are very cool and that you could customise to get exactly what you want: