I need to open in an external app (like Adobe Reader) some pdf files located inside the app (raw folder)
I try to use this code that work perfect if the files are in the SD card but, if i try to put the app (package) directory in the file line, nothing happens:
public void onClick(View v) {
File file = new File("/sdcard/myfile2.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(referencias.this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
}
}
Also i try this code. The app Adobe reader open but i receive an invalid access directory error:
public void onClick(View v) {
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse("file:///data/app/mypackage/res/raw/myfile.pdf"),
"application/pdf");
try{
startActivity(i);
}
catch (ActivityNotFoundException e) {
Toast.makeText(referencias.this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
Last solution is to copy the pdf file every time from the raw folder to the SD card, like this tutorial.
But is really complicated and a lot of code.