Pdf files as part of Android.apk

I need to create an Android application that displays a list of PDF files. These PDF files must be protected, in other words - the application user will not be able to get a copy of the PDF content in any way (copy / cut / print ... etc.). My questions now

  • How to send the contents of a pdf file with an .apk file.
  • If we send the contents of a file in diff format (raw / byte code), how can I convert the file back to pdf and where should I put the file on the installed machine so that it is safe.

FYI, I will block the current version of Adobe Redaer as a PDF viewer for viewing PDF files because it does not allow copy / paste / print.

This is the first Android app I'm developing. So, I'm kind of new to Android. Any help would be greatly appreciated.

Thanks, Navin

+4
source share
2 answers

You can copy these (these) pdf files to the resources folder, so your files will be part of your application and cannot be accessed from the outside, and you can also treat them like regular files (i.e. open with any pdf viewer in your case). Whenever you want to access the context file, you can call context.getAssets() .

We hope this information helps.

Update: Here is the code that I use to open the file in the download directory, this code can open the PDF file in any compatible PDF reader, if it is installed on the phone, tested using Adobe Reader. To run the code, you need the URI of the pdf file in the resource folder.

 String fileName = pdfUrl.substring(pdfUrl.lastIndexOf("/")); Log.i("fileName", "" + fileName); File file = new File("/sdcard/download" + fileName); // File file = new // File("/sdcard/download/airtel_latest000.mp3"); Intent intent; if (file.exists()) { Uri path = Uri.fromFile(file); intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); downloaded = true; } else { intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(pdfUrl)); downloaded = false; } try { startActivityForResult(intent, 5); } catch (ActivityNotFoundException e) { Toast.makeText(this, "No Application Available to View PDF", Toast.LENGTH_SHORT).show(); } 
+1
source

You should probably save it in res / raw folder

+1
source

Source: https://habr.com/ru/post/1340737/


All Articles