我有一个带有iFrame
的Android应用。通过这种方式,我打开了我的网站页面,该页面上有一些链接可以在新标签页中打开PDF文件。在网络上一切正常,但是在应用程序的iFrame
PDF文件中无法打开。
我尝试了所有<a>
个目标和属性download
,但是文件没有打开。
<a download href='url/mypdf.pdf' class="col-12">Open PDF</a>
答案 0 :(得分:0)
您可以在显示的Webview上使用对话框或其他东西。重要的一件事。您应该在customwebclient下面使用它在Webview上显示pdf。
public static void showWebDialog(Context activity, String url){
final Dialog dialog = new Dialog(activity, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
dialog.getWindow().setLayout(RecyclerView.LayoutParams.FILL_PARENT, RecyclerView.LayoutParams.FILL_PARENT);
dialog.setContentView(R.layout.fragment_dialog_web);
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
WebView mWebView = null;
ImageButton ib_close;
mWebView=dialog.findViewById(R.id.web_dialog);
ib_close=dialog.findViewById(R.id.img_dialog);
ib_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.setWebViewClient(new CustomWebClient(activity));
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.loadUrl(url);
dialog.show();
}
public class CustomWebClient extends WebViewClient {
@SuppressWarnings("unused") // Class tag name, used for logging
private static final String TAG = CustomWebClient.class.getSimpleName();
Context mActivity;
public CustomWebClient(Context activity) {
mActivity = activity;
}
@Override
public void onPageFinished(WebView view, String url) {
//Log.e(""+TAG,"url : "+url);
//ContentWebViewHelper.injectCSS(view);
super.onPageFinished(view, url);
}
@Override
public void onLoadResource(WebView view, String url) {
// int index = url.lastIndexOf(".");
// if (index > 0) {
// String extension = url.substring(index);
// if (extension.equals("jpg") || extension.equals("png") || extension.equals("jpeg")) {
// mActivity.displayFullscreenImage(url);
// }
// }
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
int index = url.lastIndexOf(".");
Log.d(TAG, url);
Log.d(TAG, "--index: " + index);
if (index > 0) {
String extension = url.substring(index);
if (extension.equals(".jpg") || extension.equals(".png") || extension.equals(".jpeg")) {
//mActivity.displayFullscreenImage(url);
ShowDialogHelper.showFullScreenImageDialog(mActivity,url);
}
else if(extension.equals(".pdf")){
view.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + url);
}
}
else {
view.loadUrl(url);
}
return true;
}
}