Reputation: 71
I have download pdf files in my sdcard but when i click them to open in my emulator it gives a toast
"Cannot open file" please help me to read the pdf file .... Please tell me what is wrong in this code.....
File file=new File("/sdcard/Android.Essentials.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);
startActivity(intent);
try {
startActivity(intent);
finish();
}
catch (ActivityNotFoundException e) {
Toast.makeText(PdffileActivity.this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
Upvotes: 5
Views: 18893
Reputation: 2584
You need to install any PDF Reader App in your emulator.
Your intent is looking for any installed PDF reader and in your emulator may be there is no PDF reader installed.
Just install this app in your emulator
Upvotes: 3
Reputation: 4157
To launch an Intent on a PDF file, the mobile device should have installed a program that can read PDF documents.
If you do not want the user to have a PDF reader's installed, you must modify your application to be able to read PDF documents.
On this post talk about PDF libraries for Android: Android : Is there any free PDF library for Android
Upvotes: 4