[英]How to open a pdf file given a url in android using third party application?
[英]Open PDF file in my android application without using any browser or third party application
我已經搜索了很多有關該主題的內容,但是找不到正確的答案。 謹請不要在沒有答案的情況下將其標記為重復。
我的Android應用程序中有兩個活動。
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");
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.