I can assure the in my phone I have a pdf file named "adobe.pdf" at /storage/emulated/0/Documents/adobe.pdf

I downloaded the pdf through a URL link and the stored in Documents. Here is how I downloaded it and stored it. This is another activity within the same app.


    public  void DownloadBooks(String url,String title){

        DownloadManager.Request request=new DownloadManager.Request(Uri.parse(url));
        String tempTitle=title.trim();
        request.setTitle(tempTitle);
        if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.HONEYCOMB){
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        }
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOCUMENTS,tempTitle+".pdf");
        DownloadManager downloadManager=(DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
        request.setMimeType("application/pdf");
        request.allowScanningByMediaScanner();
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
        downloadManager.enqueue(request);
    }
DownloadBooks("a link"," adobe");

After the download has completed the pdf adobe.pdf is stored at /storage/emulated/0/Documents/ and I want to view this downloaded PDF.

I am using the library to display the PDF but it is not visible. Here is my code

package com.shivansh.firebasedemo;



public class DownloadedPDFViewerActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener, OnLoadCompleteListener {
    PDFView pdfView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_downloaded_p_d_f);

        
        pdfView =findViewById(R.id.pdfView);
        File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
        File file = new File(root,"adobe.pdf");
        Log.i("5656",file.toString());
        pdfView.fromFile(file).
        enableSwipe(true)
        .defaultPage(0)
        .swipeHorizontal(false)

        .onLoad(this)
        .load();

    }
    
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public void loadComplete(int nbPages) {
    }
}

The above log statements prints

2021-05-06 03:13:31.734 9470-9470/com.shivansh.firebasedemo I/5656: /storage/emulated/0/Documents/adobe.pdf

Which suggests that I have located the correct location of the file on the device.

ScreenShot of the PDF path from my phone

Now , how do I make this pdf to render in my activity ?

0

There are 0 answers