1

I am newbie to android and development world. I need help to solve this problem.(scenario as follows)

I have created one android app using HTML5 and CSS and bundle it out using phonegap. Now I need to display PDF file in this app with two options for user whether first download and then read or second read online

So My problem is, I am not able to dispaly PDF in app. How could I achieve this? please help . I am trying to solve it from last 4 days and tried out each and solution which is already given in forum , but still no success.

It would be great for me if someone ans step by step procedure or one example to refer.

Thank You Minal

3 Answers3

0

This may help: How to open a PDF via Intent from SD card

The basic idea is to get a pdf app to render the pdf for you, and your app just kicks off an intent to do that.

Community
  • 1
  • 1
Mike T
  • 4,747
  • 4
  • 32
  • 52
0

try this code

private void openBook() {
    File file = new File(mRealPath);
    Uri path = Uri.fromFile(file);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setDataAndType(path, getString(R.string.application_type));
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(FirstTab.this, 
                getString(R.string.no_application_found), 
                Toast.LENGTH_SHORT).show();
    }
}
ShreeshaDas
  • 2,042
  • 2
  • 17
  • 36
0

you can open pdf file via intent like this

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/example.pdf"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file),”application/pdf”); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent);

Aamirkhan
  • 5,746
  • 10
  • 47
  • 74