当前位置: 首页 > 知识库问答 >
问题:

如何从firebase存储链接在我的应用程序(android studio,JAVA)中打开pdf文件

罗昊明
2023-03-14

我有pdf文件存储在我的Firebase存储,它的链接在Firebase实时数据库中,我如何在我的Android应用程序(Android Studio,JAVA)中打开它。不使用INTENT,但直接在我的应用程序中。

共有2个答案

景俊良
2023-03-14

通过很少的研究找到了答案:-不需要webview或打开另一个应用程序的意图

图书馆:-implementation'com.github.barteksc:android pdf查看器:2.8.2'

xml代码:-

 <com.github.barteksc.pdfviewer.PDFView
    android:visibility="visible"
    android:id="@+id/pdfView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

JAVA代码:-

{
 String pdfurl="firebase_access_token_of_pdf_file";

 pdfView = (PDFView) findViewById(R.id.pdfView);
 new RetrivePDFfromUrl().execute(pdfUrl);
}

 // create an async task class for loading pdf file from URL.
class RetrivePDFfromUrl extends AsyncTask<String, Void, InputStream> {
    @Override
    protected InputStream doInBackground(String... strings) {
        // we are using inputstream
        // for getting out PDF.
        InputStream inputStream = null;
        try {
            URL url = new URL(strings[0]);
            // below is the step where we are
            // creating our connection.
            HttpURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
            if (urlConnection.getResponseCode() == 200) {
                // response is success.
                // we are getting input stream from url
                // and storing it in our variable.
                inputStream = new BufferedInputStream(urlConnection.getInputStream());
            }

        } catch (IOException e) {
            // this is the method
            // to handle errors.
            e.printStackTrace();
            return null;
        }
        return inputStream;
    }

    @Override
    protected void onPostExecute(InputStream inputStream) {
        // after the execution of our async
        // task we are loading our pdf in our pdf view.
        pdfView.fromStream(inputStream).load();
    }
}
}
祁烈
2023-03-14

您可以使用android-pdfView,请参阅这篇博文。它演示了库的基本用法,通过垂直和水平滑动将pdf显示到视图上。

pdfView = (PDFView) findViewById(R.id.pdfView);
pdfView.fromFile(new File("/storage/sdcard0/Download/pdf.pdf")).defaultPage(1).enableSwipe(true).onPageChange(this).load();

还有其他一些库,比如Android PDF ViewerVuDroid等。

此外,Android API 19现在提供了在应用程序中呈现pdf内容的可行性,因此不需要第三方SDK。

你可以在这里找到详细信息。

如果要使用URL加载文件,则可以使用webview

WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true); 
String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf);
 类似资料:
  • 现在我想打开一个意图查看这个pdf文件,我已经为此使用了以下代码: 我的手机有应用程序,可以打开这个pdf文件,但它说没有安装的应用程序,以查看这个文件。 如果我在文件中转换这个url并使用下面的代码,那么应用程序的选择器被打开,但它给出了文件无法打开的错误。 多谢你提前了。

  • 问题内容: 有什么方法可以使代码以独立于平台的方式在Java应用程序中打开PDF文件?我的意思是在Windows中使用批处理文件可以做到这一点。还有其他方法可以使平台独立的代码即时打开PDF文件吗? 问题答案: 我会尝试,其中: 启动关联的应用程序以打开文件。 因此,此代码应该可以解决问题:

  • 我已经在我的设备上本地开发了一个android应用程序(应用程序还没有在android play商店上)。我有以下逻辑在主体活动中获得深度链接。 我用Firebase控制台建立了一些动态链接,并在手机浏览器中打开。但它不是打开我的应用程序并到达行字符串deepLink=appinvitereferral.getdeeplink(intent); 我在清单文件中有意图过滤器。

  • 我必须使用java应用程序打印PDF文件。我尝试过这样的方法: 当我在假打印机上测试时(我使用PDFCreator作为打印机),一切正常,但当我尝试在物理打印机上打印时,什么都没有发生。 然后我用了PDFBox。文件是打印出来的,但文字之间有奇怪的点,在不应该的地方。 那么,也许有人有从java应用程序打印PDF的经验,可以分享这些信息?

  • 我遵循了Firebase动态链接文档中的所有步骤: 已将团队Id添加到firebase控制台 已添加自定义域 启用的关联域 已添加到信息URL方案 然而,当我点击动态链接时,它总是重定向到AppStore,而不是应用程序。我已经尝试了不间断的应用程序,重新启动手机和重新安装。如何让这个深度链接发挥作用? 附注:我的应用程序还没有发布到AppStore。