將文件名從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");
layout.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>
你檢查PDF閱讀器庫? https://github.com/barteksc/AndroidPdfViewer – Youngjae
使用意圖打開該PDF文件並傳遞該文件的意圖如下,希望這會幫助你解決你的問題,它適用於我.... 私人void viewPdf(File myFile){Intent.ACTION_VIEW}; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(myFile),「application/pdf」); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent); } 此代碼將在默認PDF文件瀏覽器中打開PDF文件,或列出各種PDF查看器。 – Bhavnik
你有沒有嘗試/應用我更新的答案。 – user392117