Amit Parjapati
Amit Parjapati

Reputation: 71

how to view the pdf file in my emulator

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

Answers (3)

jazzbpn
jazzbpn

Reputation: 7348

Just download apk from this link to view Pdf files on emulator.

PdfViewerApk for Emulator

Upvotes: 2

Mihir Palkhiwala
Mihir Palkhiwala

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

Lobo
Lobo

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

Related Questions