我试图通过调用amazon url在android webview中显示pdf文件。但它只显示白色。没有加载。
当我使用其他的网址然后亚马逊它显示pdf文件在webview。我也试过这个:http://docs.google.com/gview?embedded=true&url=“+ MYURL
我也试过写URL:而且效果很好。http://www.durgasoft.com/Android%20Interview%20Questions.pdf
如果有人有什么建议,请指导我。
下面是我的代码供您参考:
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);
String url = Common.getPdfFromAmazon("52f3761d290c4.pdf");
webView.loadUrl(url);
Android Menifest.xml also give Internet Permission:
**<uses-permission android:name="android.permission.INTERNET" />**
i can also try this "http://docs.google.com/gview?embedded=true&url=" + url ;
谢谢大家。
5条答案
按热度按时间lxkprmvk1#
要显示来自亚马逊网络服务的PDF,您需要首先将PDF下载并存储到您的设备,然后通过设备上可用的PDF阅读器/查看器应用程序打开它。
1>>调用
DownloadFileAsync()
调用下载过程并传递您的Amazon Web服务URL。2>>在AsyncTask中执行下载PDF过程。
3>>下载pdf后调用
showPdfFromSdCard()
。4>>在
onResume()
中调用deletePdfFromSdcard()
qcuzuvrc2#
您需要将internet权限添加到应用程序标记之外的清单文件中。
46scxncf3#
经过2天的研究没有找到解决方案,所以我尝试首先从亚马逊网络服务下载PDF文件,并存储到SD卡,然后打开PDF文件在这里我的代码
注意:-此解决方案仅适用于从Amazon Web Service在Web视图中显示PDF。从其他Web服务尝试此代码:-
----------------------------------------------------------------------------------------------------->对于Amazon Web Service,请尝试此代码
2>>从SD卡显示PDF
下载PDF后,showPdfFromSdCard方法被调用。
后显示PDF您删除PDF文件从SD卡在这里代码删除PDF从SD卡
liwlm1x94#
请将此库添加到您的gradle文件。AndroidPdfViewer
第三步:
PDFView;
InputStream;
pdfView=findViewById(R.id.pdfView);
最终步骤:呼叫
new DownloadFileAsync().execute(url);
nhjlsmyf5#
我可能会迟到,但检查一次,网址是工作或不浏览器。
在加载到webView之前也尝试对其进行编码。
签名/签名URL也有效。