I have an image coded as base64 String, and I want to pass it in another activity,
Due to the size limit of extra in the Intent, I have used this code to store it in a temp file
FileOutputStream fos;
try {
fos = openFileOutput(imagefilename, Context.MODE_PRIVATE);
try {
fos.write(encodedPhoto.getBytes());
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
And I have passed the imagefilename in another activity,
In the new Activity I have used this code to read it
try {
FileInputStream fis = openFileInput(imagefilename);
String strLine = null;
StringBuffer buffer = new StringBuffer();
DataInputStream dataIO = new DataInputStream(fis);
if ((strLine = dataIO.readLine()) != null) {
buffer.append(strLine);
}
dataIO.close();
fis.close();
encodedPhoto = strLine;
} catch (NullPointerException e) {
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
However in this way I cannot read correctly the original encoded Base64 photo…
I don’t get any error however the String of the encoded image(encodedPhoto) read, seems corrupted
How I can fix this problem?
Your read method is wrong,
Try to use this code:
In this way you can read the String content of the file without modification.