In my application i want to store a PDF file in assets and when the view button is pressed , the PDF should be viewed by 3rd party applications installed in the device.
By using the below code , i tried to access the PDF file inside assets folder but app says 'File not available' . I searched over stackoverflow for various code and none of them worked.But when i tried to extract the APK file i could be able to see the PDF file inside assets folder.
The following is the code i tried :
File file = new File("file://" + getFilesDir() + "/ccv.pdf");
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(home.this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
}
else
{
Toast.makeText(home.this,
"File not available",
Toast.LENGTH_SHORT).show();
}
So please provide the code snippet to access PDF file inside assets folder.
Thanks in advance