gpt4 book ai didi

android - 将 PDF 加载到 android webview

转载 作者:行者123 更新时间:2023-11-29 00:17:37 25 4
gpt4 key购买 nike

在我的 android 应用程序中,我必须将服务器中的 PDF 加载到 webview 中。根据一个堆栈溢出问题,我在加载它时使用了 Google DOC View 。但我的问题是有时它不会在 webview 中显示文件,而在另一个实例中它显示得很好。我无法弄清楚问题所在。但代码似乎没问题。我的代码段如下。

WebViewLable.getSettings().setJavaScriptEnabled(true);    
WebViewLable.getSettings().setLoadWithOverviewMode(true);
WebViewLable.getSettings().setUseWideViewPort(true);

fullURL=GoogleDOCview+"https://livefarmer.com/labels/"+itemURL;
WebViewLable.loadUrl(fullURL);

}

private class Callback extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(
WebView view, String url) {
return(false);
}
}

我的 WebView 如下。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/app_bg_black"
android:orientation="vertical" >

<include
android:id="@+id/nav_bar"
android:layout_width="fill_parent"
layout="@layout/nav_bar" />


<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webViewLable"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:windowSoftInputMode="adjustResize" />

</LinearLayout>

这是未显示 pdf 时的 logcat 输出。

enter image description here

这是在 webview 中显示 pdf 时的 logcat 输出。

enter image description here

所以我的代码有什么问题。我怎样才能解决这个问题。谢谢和问候!

最佳答案

String PdfUrl = "http://pdfexample.com/abcd.pdf";
String url = "http://docs.google.com/gview?embedded=true&url=" + PdfUrl;
Log.i(TAG, "PDF URL : " + url);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);

试试这个

关于android - 将 PDF 加载到 android webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25522864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com