Android 联系人图标存储技术
我想知道存储本地电话联系人图标的最佳方式是什么。我正在编写一个管理器,允许用户选择要在列表中显示的联系人,现在需要显示联系人图标。
是否会将图标存储在选择工作的不同位置,或者我应该尝试存储图标位置并以这种方式链接到它的路线?经历过这个的人可以给我指出正确的方向吗?我已经使用 Sqlite 数据库来存储联系人。
任何代码/链接都会非常有帮助。
I'm wondering what the best way to store a local phone contact's icon is. I'm writing a manager that will allow the user to select contacts for display in a list which now needs contact icon display.
Would storing the icon in a different location on select work or should I try the route of storing the location of the icon and linking to it that way? Can anyone who has went through this already point me in the right direction? I'm using an Sqlite database to store the contacts already.
Any code/links would be very helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您已经将联系人存储在 Sqlite 数据库中,因此我只需向该数据库添加另一个字段来保存编码图像。
我解决类似问题的方法是:我使用 Base64 来编码图像到一个字符串中,然后我将该字符串存储在任何我想要的地方...
我在 Base64 类中添加了一个函数来直接为我编码 Bitmap 对象并返回一个字符串,代码如下:
其中
encodeBytes(buffer)< /code> 已经Base64 类的实现函数。
这将是比存储图像路径更好的方法,因为用户可以轻松更改路径,然后您的应用程序将不再找到该图片。
希望有帮助。
Since you are already storing the contacts in an Sqlite db, I'd just add another field to that db that will hold an encoded image.
The way I have gone to solve a similar issue is: I used Base64 for encoding an image into a String and then I store that String wherever I want...
I added one function to the Base64 class to directly encode a Bitmap object for me and return a String, here's the code:
where
encodeBytes(buffer)
is already an implemented function of the Base64 class.This would be a better way of doing it than storing the path to the image, because a user can easily change the path and then your application wouldn't find the picture anymore.
Hope that helps.
首先,我建议查看 Android 源代码并了解他们是如何做到的。
除此之外,如果图像很小,我强烈建议创建一个适当的 ContentProvider 并使用 Cursor.getBlob() 将图像存储为附加到行的二进制 blob。请参阅 http://developer.android.com /intl/de/guide/topics/providers/content-providers.html#querying 了解更多详细信息。
对于较大的图像,请查看如何存储大图像Android 内容提供程序中的 blob?
First, I'd recommend looking at the Android source and seeing how they do it.
That aside, if the images are smallish, I'd highly recommend creating a proper
ContentProvider
and storing the images as binary blobs attached to the row usingCursor.getBlob()
. See http://developer.android.com/intl/de/guide/topics/providers/content-providers.html#querying for more details.For larger images, take a look at How to store large blobs in an android content provider?