How to open pdf file in package path in android?

In my application, I need to open a pdf file. For this, I prepared the code for opening a pdf file. Suppose my pdf file is in sdcard, it works fine. When my application changes from sdcard to the application path, i.e. /data/data/app.package/ it does not work. I got an Invalid file path warning dialog. Please help me solve this problem.

+4
source share
3 answers

/data/data/app.package/ is a closed package. To share this pdf, you probably have to move it to external storage (you can use getExternalFilesDir () ). This directory is not secure.

0
source

By Android document

You can save files directly to the internal memory of the device. By default, files stored in the internal storage are private for your application, and other applications cannot access them (and also cannot). When a user uninstalls your application, these files are deleted.

 String string = "hello world!"; FileOutputStream fos = openFileOutput("HERE YOUR FILENAME", Context.MODE_PRIVATE); fos.write(string.getBytes()); fos.close(); 
+1
source

You must make /data/data/app.package/file.pdf re-accessible to other applications.

1) using openFileOutput (fname, Context.MODE_WORLD_READABLE) .close (); create a shared file in the data directory of your application.

2) write the pdf file to the created file using Streams (you can write to the returnet stream using openFileOutput rather than closing it)

3) open the pdf file

+1
source

All Articles