I'm programming an app that receives all kind of documents as base64 strings. I've been searching all morning, and I didn't find a way to display the documents properly without storing them. As an alternative I wrote this:
private void createReadableFile(DocumentBinary document) {
try {
byte[] bytes = Base64.decode(document.getDocument(), 0);
FileOutputStream os = openFileOutput(document.getSuggestedFileName(), MODE_PRIVATE);
os.write(bytes);
os.flush();
os.close();
openFile(document);
} catch (Exception e) {
Ln.e(e, "Error while parsing document");
}
}
And I do this with the created file:
private void openFile(File file, String mimeType) {
Intent viewIntent = new Intent();
viewIntent.setAction(Intent.ACTION_VIEW);
viewIntent.setDataAndType(Uri.fromFile(file), mimeType);
viewIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(viewIntent);
}
But it doesn't start anything. It calls onPause and onResume but nothing happens. I know that if I change MODE_PRIVATE to MODE_WORLD_READABLE it would work, but MODE_WORLD_READABLE is deprecated. Do you know a better way to do it or what to use instead of MODE_PRIVATE?