【问题标题】:Android pass base64 string to another activity with intentAndroid将base64字符串传递给另一个有意图的活动
【发布时间】:2015-09-29 07:08:53
【问题描述】:

如何将base64 编码的字符串传递到另一个页面。我已经尝试过了,但是当这段代码运行时程序会冻结

base64String= base64FromBitmap(capturedImage);
intent.putExtra("BASE64IMAGE", base64String]); // Freezes on this line

这是base64 convert 方法。它可以正常工作

private static String base64FromBitmap(Bitmap bmp){
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();  
        bmp.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
        byte[] byteArray = byteArrayOutputStream .toByteArray();
        String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
        return encoded;
    }

【问题讨论】:

  • 您不能在活动之间传递大数据。我想有一个 1MB 的限制。 (我在某处读过)
  • 您可以做的是将其存储在文件存储中并在另一个活动中将其取回
  • 您可以获取图像的路径并按意图发送,而不是在 B64 中发送图像
  • @RaviGadipudi 谢谢你的建议。我怀疑在这种情况下。和之前一样保存文件,我会发送文件路径。

标签: android android-intent bitmap base64


【解决方案1】:

问题在于您发送的图像远大于要存储在意图中的预期数据大小。

我建议您改为将图像保存到存储中,然后获取存储的路径并将其发送。这将大大提高速度,并减少损坏数据的机会。

See this tutorial on how to store the image data

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多