File file = new File("android.resource://com.baltech.PdfReader/assets/raw/"+filename);
if (file.exists()) {
Uri targetUri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/pdf");
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(PdfReaderActivity.this, "No Application Available to View PDF", Toast.LENGTH_SHORT).show();
}
i want to read .pdf file which is in assets folder. what path i hav to give in filename. plz help. Thanks
Since assets files are stored inside apk file, there is no absolute path of the assets folder. You might use a workaround creating a new file used as a buffer.
You should use AssetManager:
I'm not sure if you got an answer to this already, seems pretty old, but this worked for me.
The CreateFileFromInputStream function is as follows
Really hope this helps anyone else who reads this.
replace the above line with below and try..
and place your PDF file raw folder instead of asset. Also change com.com.com with your package name.