1

I'm currently trying to use dynamic delivery to download and install some pdf files and open them with barteksc's pdf viewer (com.github.barteksc:android-pdf-viewer:2.8.2).

When I had the pdf files inside my apk everything worked fine but now that I download them and install them via dynamic delivery I get this error when I try to open them

E/PDFView: load pdf error java.io.FileNotFoundException: Example.pdf at android.content.res.AssetManager.nativeOpenAsset(Native Method) at android.content.res.AssetManager.open(AssetManager.java:744) at android.content.res.AssetManager.open(AssetManager.java:721) at com.github.barteksc.pdfviewer.util.FileUtils.fileFromAsset(FileUtils.java:37) at com.github.barteksc.pdfviewer.source.AssetSource.createDocument(AssetSource.java:39) at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:53) at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:25) at android.os.AsyncTask$2.call(AsyncTask.java:333) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:764)

This returns "Installed"

if (manager.getInstalledModules().contains("dynamicfeature")) {
            statusText.setText("Installed");
        } else {
            statusText.setText("Feature not yet installed");
        }

I am installing the module from a different Class if that makes a difference, I saw something about updating the context in Google docs but I could not figure it out.

I have also added

com.google.android.play.core.splitcompat.SplitCompatApplication

as the documentation says, still no luck.

This is the method I am using to view the Pdf file.It was working perfect while the pdfs where in the asset folder of the base application but it's not working now that the pdfs are in the assets folder of the Dynamic Delivery Module.

private void displayFromAsset(String assetFileName) {
        String SAMPLE_FILE = getIntent().getStringExtra("PDF INTENT");
        pdfFileName = assetFileName;

         pdfView.fromAsset(SAMPLE_FILE)
                .defaultPage(pageNumber)
                .enableSwipe(true)

                .swipeHorizontal(false)
                .onPageChange(this)
                .enableAnnotationRendering(true)
                .onLoad(this)
                .scrollHandle(new DefaultScrollHandle(this))
                .load();
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Gerasimos
  • 83
  • 8

1 Answers1

0

Example.pdf is not pointing to the asset folder.

you need to provide a relative patht of your file . for asset folder u can giv like

Uri resUri= Uri.fromFile(new File("//android_asset/image.png"));

For downloaded pdf files you can query by contentprovider query & get the uri from query result.

Rajesh Gopu
  • 863
  • 9
  • 33
  • I've updated my question with the actual method I use to view the pdfs.It's the basic one for the pdf viewer library. – Gerasimos Sep 23 '19 at 11:20