Hello Support,
This is our code:
• Downloading pdf to local storage:
@Override
public void run(){
saveOnDisk(pdfB, listener);
}
private void saveOnDisk(final byte[] bytesPDF, final DownloadPdfFileListener pdfListener ){
new Thread(){
@Override
public void run(){
writeFileToDisk(bytesPDF, pdfPath, Utilities.md5(url));
sendMessage(bytesPDF, (pdfPath + Utilities.md5(url)), pdfListener);
}
}.start();
}
public static boolean writeFileToDisk(byte[] rawData, String path, String fileName){
boolean result = false;
FileOutputStream fos;
try{
if(rawData != null && rawData.length > 0){
File dir = new File(path);
if(!dir.exists()){
dir.mkdirs();
}
fos = new FileOutputStream(new File(path + fileName));
fos.write(rawData);
fos.flush();
fos.close();
result = true;
}
} catch (FileNotFoundException e) {
Log.w(TAG, "writeFileToDisk() FileNotFoundException: " + e.getMessage());
} catch (IOException e) {
Log.w(TAG, "writeFileToDisk() IOException: " + e.getMessage());
}
return result;
}
private void sendMessage(final byte[] bytes ,final String pathLocalPDF, final DownloadPdfFileListener pdfListener ){
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
if(pdfListener != null){
pdfListener.onPdfReady(bytes, pathLocalPDF);
}
}
},1000);
}
• Renderization:
private void renderPDF(byte[] pdfStream, CustomPDFReader pdfReader) {
View v = getView();
if (v != null) {
if (pdfStream != null && pdfStream.length > 0) {
Document pdf = new Document();
int result = pdf.OpenMem(pdfStream, v.getContext().getString(R.string.pdf_key));
logResult(result);
pdfReader.PDFOpen(pdf, pdfReader);
pdfReader.setVisibility(View.VISIBLE);
pdfReader.setOverScroll(overScroll);
} else {
Utilities.showCustomToast("No se logró descargar la página.", Toast.LENGTH_SHORT, Utils.TOAST_CENTER, v.getContext());
}
showProgress(v, false);
}
}
We install this app in some devices and we realized using the message text "AvialMem:" (Available memory) that the memory consumption in devices having
Android 11+ is greater than devices having
Android 10--.
Tests when pdf is rendered:
• One Plus Nord Android 11: AvialMem 1710 M
• Pixel 3 Android 12 Beta: AvialMem 1017 M
• Huawei Y9 Android 9: AvialMem 779 M
Most of the time when we open the pdf in Android 11+ the screen freezes and an ANR message appears on the screen (you can see in the GIF when we open the pdf in
Android 11) while in
Android 9 the PDF is rendered without any problem and we can paginate.
Gif One Plus Nord Android 11:
drive.google.com/file/d/1U9kuPyBsHFKZXe_...HQq/view?usp=sharing