1

my code is here

 File file = new File(mediaData.getMediaUrl());
    Uri path = Uri.fromFile(file);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(path, "application/pdf");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent).

getting error pdf is not display

UJWAL GHONGADE
  • 109
  • 1
  • 9

2 Answers2

1

I've implemented this feature using pdfViewer and adding some logic. I used rxJava2 for multithreading, because Android forbids to use network requests in main thread.

 disposables.add(getInputStreamFromUrl(urlResource!!)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe({
                        pdfView.fromStream(it)
                                .defaultPage(0)
                                .enableSwipe(true)
                                .autoSpacing(true)
                                .onLoad {
                                    hideProgressDialog()
                                }
                                .onError {
                                    hideProgressDialog()
                                    showInfoDialog(it.message, true)
                                }
                                .load()

                    }, {
                        hideProgressDialog()
                        showInfoDialog(it.message, true)
                    })
            )

And getInputStreamFromUrl() method:

private fun getInputStreamFromUrl(url: String): Single<InputStream> {
    return Single.defer {
        Single.just(URL(url).openStream())
    }
}

I hope this will help!

-1

Using this library, you can even display a remote PDF :
https://github.com/voghDev/PdfViewPager

Sahil Munjal
  • 463
  • 2
  • 15