1

Hi in my project i'm reading Pdf file from the Assets folder. I am able to read the Pdf file from Assets folder. And only thing is i must move automatic to another activity when i reach the final page of the Pdf. Here is the code i used to read the Pdf file form the Assets.

 private void CopyReadAssets()
    {
        AssetManager assetManager = getAssets();

        InputStream in = null;
        OutputStream out = null;
        File file = new File(getFilesDir(), "apple.pdf");
        try
        {
            in = assetManager.open("bplayamgroup.pdf");
            out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);

            copyFile(in, out);
            in.close();
            in = null;
            out.flush();
            out.close();
            out = null;
        } catch (Exception e)
        {
            Log.e("tag", e.getMessage());
        }

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(
                Uri.parse("file://" + getFilesDir() + "/apple.pdf"),
                "application/pdf");

        startActivity(intent);
    }
  private void copyFile(InputStream in, OutputStream out) throws IOException
    {
        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) != -1)
        {
            out.write(buffer, 0, read);
        }
    }

I'm stuck in this for 1 week.

Jagan
  • 692
  • 1
  • 12
  • 38
  • Which library you are using to read PDF? You have to check if there are means to have listener on page change or have a background job that will do this and if page is on the last of pdf you just open another activity. – Lukasz 'Severiaan' Grela Nov 28 '13 at 08:00
  • 1
    @Lukasz'Severiaan'Grela i'm not using any lib file i'm calling the inbuilt intent type intent.setDataAndType(Uri.parse("file://" + getFilesDir() + "/apple.pdf"),"application/pdf"); – Jagan Nov 28 '13 at 08:58
  • so you dont have (your app) any clue what is happening after spawning this intent. maybe try to actually have a built-in pdf viewer? – Lukasz 'Severiaan' Grela Nov 28 '13 at 11:08
  • @Lukasz'Severiaan'Grela how can i have a built-in pdf viewer in that i can get the last page? – Jagan Nov 28 '13 at 12:31
  • [Here](http://stackoverflow.com/questions/16630382/how-to-enable-pinch-zoom-on-a-web-view-loading-a-url-with-pdfandroid) are some details, but I think it will not work very well, why do you need this functionality? – Lukasz 'Severiaan' Grela Nov 28 '13 at 13:15

1 Answers1

1

Used flag value for the pdf reader intent. Start the flag when You click on the PDF intent.When you click the back button check the flag in the on resume with this we can find it has been used or not