Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top