3

How can I pass a base64 encoded string to another page. I have tried with this but the program freezes when this code running

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

This is the base64 convert method. It works without problems

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;
    }
IKavanagh
  • 6,089
  • 11
  • 42
  • 47
Junior Develepor
  • 192
  • 2
  • 18

1 Answers1

3

The issue is that the image you are sending is a lot bigger than the intended size of data to be stored in intents.

What I would advise you do instead is save the image to storage, and then get the stored path and send that instead. This will greatly improve the speed, and reduce the chance of corrupting data.

See this tutorial on how to store the image data

Andrew Breen
  • 685
  • 3
  • 11