打开存储在 Firebase 存储中的 pdf 文件 url

Pri*_*one 5 pdf android firebase firebase-storage

我已将 Pdf 文件上传到 firebase 存储,将 pdf 文件上传到 firebase 存储后,我得到了下载网址。现在我想在我的应用程序中打开此下载网址中的 pdf 文件。

以下是我将 pdf 文件上传到 firebase 存储后得到的 url。

https://firebasestorage.googleapis.com/v0/b/realtime-chat-46f4c.appspot.com/o/documents%2Fbf307aa5-79ae-4532-8128-ee394537b357.pdf?alt=media&token=2d0c5329-4717-4adc- 9418-6614913e5bfa

现在我想打开一个意图来查看此 pdf 文件,我为此使用了以下代码:

String url = "https://firebasestorage.googleapis.com/v0/b/realtime-chat-46f4c.appspot.com/o/documents%2Fbf307aa5-79ae-4532-8128-ee394537b357.pdf?alt=media&token=2d0c5329-4717-4adc-9418-6614913e5bfa";

Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "application/pdf");
startActivity(Intent.createChooser(intent, "Choose an Application:"));
Run Code Online (Sandbox Code Playgroud)

我的手机有可以打开此 pdf 文件的应用程序,但它仍然显示没有安装可查看此文件的应用程序。

如果我在文件中转换此 url 并使用以下代码,则应用程序的选择器将打开,但会出现无法打开文件的错误。

Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
File file = new File(name);
intent.setDataAndType(Uri.fromFile(file), "aplication/pdf");
Run Code Online (Sandbox Code Playgroud)

我看到很多答案都说先下载文件然后打开它,但我不想下载文件,我只想查看它。

如果有人对此有任何想法,请帮助我。

非常感谢。

Hit*_*lot -4

使用Webview查看pdf文件-

 WebView webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);
    String pdf = "https://firebasestorage.googleapis.com/v0/b/realtime-chat-46f4c.appspot.com/o/documents%2Fbf307aa5-79ae-4532-8128-ee394537b357.pdf?alt=media&token=2d0c5329-4717-4adc-9418-6614913e5bfa";
    webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
Run Code Online (Sandbox Code Playgroud)