Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在Room数据库(Java)中存储url中的图像_Android_Android Room - Fatal编程技术网

Android 如何在Room数据库(Java)中存储url中的图像

Android 如何在Room数据库(Java)中存储url中的图像,android,android-room,Android,Android Room,我将整个API响应发送到Room数据库,以便脱机访问。 我已经设法存储了所有的字符串值,但我也想将图像(获取图像url的响应)存储到数据库中。 由于我没有使用Room数据库的经验,我对如何在Room db列中存储图像感到困惑 下面是API的响应 { "beast": [{ "id": "1", "name": "The Griffin of Edward III", "description": "The English Beast has alw

我将整个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)
注释房间模型类中的图像字段。有关详细信息,请观看此内容。

您应该使用BLOB数据类型来存储图像。只需使用
@ColumnInfo(typeAffinity=ColumnInfo.BLOB)
注释房间模型类中的图像字段。有关详细信息,请观看此图片。

您可以将图像作为blob类型存储在房间DB中。 您应该将图像转换为字节数组并保存它。 例如:

@ColumnInfo(name = "image", typeAffinity = ColumnInfo.BLOB)
private byte[] image;

您可以将图像作为blob类型存储在room DB中。 您应该将图像转换为字节数组并保存它。 例如:

@ColumnInfo(name = "image", typeAffinity = ColumnInfo.BLOB)
private byte[] image;

这回答了你的问题吗@ManthanTilva我得到了图像url的响应,我想将其存储为房间数据库中的图像将图像保存为blob/字节数组或房间数据库中的base64字符串这是否回答了您的问题@ManthanTilva我得到了图像url的响应,我想将其存储为房间数据库中的图像将图像保存为blob/字节数组或房间数据库中的base64字符串getting com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:应为BEGIN_数组,但在第1行第2104列的字符串路径$.beastData[0].形象error@VinodPatil添加一些代码,这会导致此异常Getting com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:应为BEGIN_数组,但在第1行第2104列path$.beastData[0]处为字符串。imageerror@VinodPatil添加一些代码,这会导致异常设置JsonSyntaxException,应为BEGIN_数组,但在第1行第2104列路径$.beastData[0]处为字符串。imagegetting JsonSyntaxException,应为BEGIN_数组,但在第1行第2104列路径$.beastData[0]处为字符串。image