android - WebView 不在模拟器上加载内容

标签 android webview android-emulator

我尝试阅读其他主题,但对我没有任何帮助,所以我提出了这个新问题。

我有一个包含 webView 的 Activity ,但内容似乎没有加载(在模拟器上,因为这是我现在唯一的“设备”)。

这是我的代码: 公共(public)类 WebViewActivity 扩展了 AppCompatActivity{

WebView webView;
private ProgressDialog progressBar;
String link;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_web);

    // Hide action bar
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.hide();
    }

    webView = (WebView) findViewById(R.id.webView);

    Intent intent = getIntent();
    link = (String) intent.getSerializableExtra(Constants.intentForWebView);

    progressBar = ProgressDialog.show(this,"loading","please wait");
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.setWebViewClient(new MyWebViewClient());

    webView.loadUrl(link);

}

private class MyWebViewClient extends WebViewClient {

    @Override
    public void onPageFinished(WebView view, String url) {
        if (progressBar != null && progressBar.isShowing()) {
            progressBar.dismiss();
        }
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        return super.shouldOverrideUrlLoading(view, request);
    }
}
}

添加了 LogCat

1-07 23:46:39.422 11215-11215/com.android.xxx D/cr_Ime: [InputMethodManagerWrapper.java:59] isActive: false
01-07 23:46:39.506 11215-11215/.xxx   I/cr_Ime: ImeThread is not enabled.
01-07 23:46:39.521 11215-11568/.xxx E/chromium: [ERROR:gles2_cmd_decoder.cc(2167)] [GroupMarkerNotSet(crbug.com/242999)!:54278386]GL ERROR :GL_INVALID_OPERATION : BackFramebuffer::Create: <- error from previous GL command
01-07 23:46:39.671 11215-11220/.xxx I/art: JIT allocated 61KB for compiled code of void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
01-07 23:46:39.671 11215-11220/.xxx I/art: Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
01-07 23:46:39.743 11215-11333/com.android.xxx.xxx 
E/EGL_emulation: tid 11333: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
01-07 23:46:39.743 11215-11333/.xxx W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x8173c680, error=EGL_BAD_MATCH
01-07 23:46:39.860 11215-11333/.xxx E/EGL_emulation: tid 11333: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
01-07 23:46:39.860 11215-11333/.xxx W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x8173cd60, error=EGL_BAD_MATCH
01-07 23:46:39.962 11215-11215/.xxx W/art: Attempt to remove non-JNI local reference, dumping thread
01-07 23:46:39.972 11215-11226/.xxx I/art: Background sticky concurrent mark sweep GC freed 4437(348KB) AllocSpace objects, 5(100KB) LOS objects, 0% free, 65MB/65MB, paused 6.043ms total 30.859ms
01-07 23:46:40.294 11215-11215/.xxx W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 11215
01-07 23:46:40.536 11215-11215/.xxx W/art: Attempt to remove non-JNI local reference, dumping thread
01-07 23:46:40.624 11215-11222/.xxx W/art: Suspending all threads took: 14.950ms
01-07 23:46:40.642 11215-11226/.xxx I/art: Background partial concurrent mark sweep GC freed 325(10KB) AllocSpace objects, 1(7MB) LOS objects, 7% free, 50MB/54MB, paused 7.109ms total 32.209ms
01-07 23:46:41.379 11215-11215/.xxx W/art: Attempt to remove non-JNI local reference, dumping thread
01-07 23:46:41.454 11215-11215/.xxx W/art: Attempt to remove non-JNI local reference, dumping thread
01-07 23:46:41.519 11215-11215/.xxx W/art: Attempt to remove non-JNI local reference, dumping thread
01-07 23:46:41.597 11215-11215/.xxx W/art: Attempt to remove non-JNI local reference, dumping thread
01-07 23:46:41.674 11215-11215/.xxx W/art: Attempt to remove non-JNI local reference, dumping thread
01-07 23:46:41.735 11215-11215/.xxx W/art: Attempt to remove non-JNI local reference, dumping thread

最佳答案

解决了!

问题似乎出在没有有效证书的情况下加载站点时。在模拟器中添加带有证书的 url

关于android - WebView 不在模拟器上加载内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41527055/

相关文章:

android - Dart/flutter 每次之后如何定期更改计时器

android volley发布json ID并从PHP服务器返回结果

android - webview,文件输入字段文件选择器不显示

java - 如何解决默认 Activity 未找到问题?

android - 创建新的 AVD,检查快照和使用主机 GPU

java - 如何使按钮不可点击但可触摸?

Android Junit 测试 Button 已经开始 Activity

java - 如何在 WebView Android Studio 中打开本地 pdf 文件

swift - 如何在 OneSignal Swift 中显示特定的 ViewController

Android 模拟器无法运行