gpt4 book ai didi

android - 从url在Android Webview中查看pdf文件

转载 作者:搜寻专家 更新时间:2023-11-01 07:55:20 24 4
gpt4 key购买 nike

我正在尝试从这个 url 在 Android WebView 中打开一个 pdf 文件:

http://bijsluiters.fagg-afmps.be/registrationSearchServlet?key=BE-TU441865&leafletType=leafletNL

当我在网上搜索有关如何实现此目的的信息时,我发现你需要在它前面用这个扩展 url:“http://docs.google.com/gview?embedded=true&url=

但是当我这样做时,我只能看到 html,就像您在浏览器中打开链接时一样:"https://docs.google.com/gview?embedded=true&url=http://bijsluiters.fagg-afmps.be/registrationSearchServlet?key=BE-TU441865&leafletType=leafletNL "

如何在我的 webview 中看到实际的非 html 内容?

public class BijsluiterFragment : Android.Support.V4.App.Fragment
{
//Title = DomainController.Instance.GetWord("BijsluiterTitle");
private View view;
private WebView webview;
private string url;

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
view = inflater.Inflate (Resource.Layout.BijsluiterFragment, container, false);
webview = view.FindViewById<WebView> (Resource.Id.webView);
webview.Settings.JavaScriptEnabled=true;
webview.Settings.SetPluginState (WebSettings.PluginState.On);
if(!String.IsNullOrEmpty(url))
{
webview.LoadUrl ("http://docs.google.com/gview?embedded=true&url="+url);
}
return view;
}

public void SetUrl(string url)
{
this.url = url;
}
}

我也尝试过“loadwithbaseurl”方法,但它也没有用...

最佳答案

我用这个解决了同样的问题:

if (url.endsWith(".pdf")) {
try {
String urlEncoded = URLEncoder.encode(url, "UTF-8");
url = "http://docs.google.com/viewer?url=" + urlEncoded;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}

}

使用此前缀:“http://docs.google.com/viewer?url=”,WebView 使用 GoogleDocs 打开 pdf。

希望对你有帮助!!

关于android - 从url在Android Webview中查看pdf文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28547649/

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