gpt4 book ai didi

java - WebView 中的图像未加载

转载 作者:行者123 更新时间:2023-12-02 03:27:13 25 4
gpt4 key购买 nike

由于某种原因,我的 WebView 中的图像未加载。即使在这里尝试了多种解决方案后,我也不明白为什么。请帮我解决这个问题。

我的应用程序WebView

enter image description here

我的 AVD 浏览器 View

enter image description here

页面链接为here

我的WebViewActivity

public class WebViewActivity extends Activity{

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);

final WebView webview = (WebView) findViewById(R.id.webView);
//TextView contentView = (TextView) findViewById(R.id.contentView);


Intent intent = getIntent();
String address = intent.getStringExtra("URL");


webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {

}
});


webview.getSettings().setLoadsImagesAutomatically(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.loadUrl(address);


//textToSpeech.speak("TALK", TextToSpeech.QUEUE_FLUSH, null);


}

}

最佳答案

这是一个mixed content问题是因为您在 Web View 中使用 https 协议(protocol)时调用 http 协议(protocol)。

使用 setMixedContentMode(int mode) 更改混合内容模式:

webview.getSettings().
setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);

来自Android doc对于MIXED_CONTENT_COMPATIBILITY_MODE:

Used with setMixedContentMode(int) In this mode, the WebView will attempt to be compatible with the approach of a modern web browser with regard to mixed content. Some insecure content may be allowed to be loaded by a secure origin and other types of content will be blocked. The types of content are allowed or blocked may change release to release and are not explicitly defined. This mode is intended to be used by apps that are not in control of the content that they render but desire to operate in a reasonably secure environment. For highest security, apps are recommended to use MIXED_CONTENT_NEVER_ALLOW.

关于java - WebView 中的图像未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38674655/

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