我已经在这个主题上搜索了很多,但我无法找到正确的答案。我恳请不要在没有答案的情况下将其标记为重复。
我的安卓应用程序中有两个活动。
1). 单击任何文件时服务器上可用的PDF文件列表 开始下载并显示进度条,直到下载完成。下载完成后,弹出两个按钮[查看]或[取消]被打开。单击"查看"打开第二个活动,将 PDF 文件路径作为参数传递。
2]。在第二个活动中,我想打开仅在应用程序活动中有意传递的PDF文件。
我不想使用任何浏览器,驱动器,文件管理器或任何外部Android应用程序。
我如何实现这一目标,请为我提供适当的解决方案。提前谢谢你:)
将文件名从 FirstActivity 发送到 SecondActivity。
Intent i=new Intent(FirstActivity.this, SecondActivity.class);
i.putExtra("file", fileUrl);
startActivity(i);
在 SeconActivity 中,使用 WebView
编辑
Intent i = getIntent();
String myPdfUrl = i.getStringExtra("file");
String url = "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl;
String doc="<iframe src='"+url+"' width='100%' height='100%' style='border: none;'></iframe>";
WebView web=(WebView)findViewById(R.id.webViewpdf);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadData(doc, "text/html", "UTF-8");
布局.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webViewpdf"/>
</LinearLayout>