我正在构建Android应用程序,我在webview中放置了链接到多个链接指向PDF的页面。每天都会更新新链接。我想制作这样的功能:当用户点击特定的PDF链接时,它应该在默认的PDF查看器中打开或者在其自身中打开。
目前,当用户点击webview中的PDF链接时,没有任何事情发生。
WebView w=(WebView)findViewById(R.id.web1);
WebSettings webSettings=w.getSettings();
webSettings.setDomStorageEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
w.setWebViewClient(new WebViewClient());
w.loadUrl("http://collegecirculars.unipune.ac.in/sites/examdocs/_layouts/mobile/view.aspx?List=7ed6607e-6c43-401a-a922-bf8d8bf08ed8&View=dc261157-c533-4a60-977b-506fd87b2a19");
答案 0 :(得分:0)
您可以使用Google文档查看器在线阅读您的PDF格式:
WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
String pdf = "http://collegecirculars.unipune.ac.in/sites/examdocs/Examiantions%20Timetables/Master-In-ARTS(M.A)(Rev.2008)-(24908)_Spl4-8-16.pdf?Mobile=1&Source=%2Fsites%2Fexamdocs%2F_layouts%2Fmobile%2Fview%2Easpx%3FList%3D7ed6607e%252D6c43%252D401a%252Da922%252Dbf8d8bf08ed8%26View%3Ddc261157%252Dc533%252D4a60%252D977b%252D506fd87b2a19%26ViewMode%3DSimple%26CurrentPage%3D1";
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
在浏览器中打开
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(pdf_url));
startActivity(browserIntent);
覆盖当前网址:
private class MyWebViewClient extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
// here you can check PDF
url = url.toLowerCase();
view.loadUrl(url);
return true;
}
}
将此MyWebViewClient设置为您的webView。
PaymentWebViewClient paymentWebViewClient = new PaymentWebViewClient();
webView.setWebViewClient(paymentWebViewClient);