android - 如何在 Room 数据库中存储来自 url 的图像 (Java)

标签 android android-room

我正在将整个 API 响应发送到 Room 数据库以供离线访问。 我已经设法存储了所有字符串值,但我也想将图像(获取图像 url 作为响应)存储到数据库中。 由于我没有使用 Room 数据库的经验,我对如何将图像存储在 Room db 列中感到困惑 以下是 API 响应

{
"beast": [{
        "id": "1",
        "name": "The Griffin of Edward III",
        "description": "The English Beast has always been a lion",
        "image": "www.google.com/uploads/beast-images/2.png"
    },
    {
        "id": "2",
        "name": "The Lion of England",
        "description": "The English Beast has always been a lion",
        "image": "www.google.com/uploads/beast-images/2.png"
    }]
}

最佳答案

您应该使用 BLOB 数据类型来存储图像。只需使用 @ColumnInfo(typeAffinity = ColumnInfo.BLOB) 注释 Room 模型类中的图像字段。看这个answer获取更多信息。

关于android - 如何在 Room 数据库中存储来自 url 的图像 (Java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59488268/

相关文章:

android - gradle中的android studio firebaseui版本

Android - 如何取消选择 ActionBar 中的所有选项卡

java - Android ViewModel 和 Paging 3 库

sqlite - session 室数据库迁移失败 : ALTER TABLE to add multiple columns

Android - 多数据库一个项目

android - 如何使用过多的 Completable 方法执行顺序操作

android - 来自 android : Oauth framework user didn't match oauth token user 的云端点身份验证

java - 如何在 ViewPager Fragment 中更改 View

android - Parse.com 不保存 ParseObjects

android-room - 如何抑制android-room警告: Primary key constraint on id is ignored when being merged into Foo