安卓应用程序无法在模拟器上连接到互联网

3
该应用程序无法连接到互联网。 我已经尝试过重新启动设备和检查网络连接,但问题仍然存在。
<uses-permission android:name="android.permission.INTERNET" />

在我的清单文件中,我检查了模拟器上的其他应用程序(例如YouTube和Google搜索),它们都能正常工作,但该应用程序无法加载页面。这是我的主要Java文件。

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;


public class MainActivity extends Activity {


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

        WebView myWebview ;
        myWebview  = (WebView) this.findViewById(R.id.webz);

        myWebview.loadUrl("https://en.wikipedia.org/");

    }

}

and this is my main activity

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.hoda.myapplication.MainActivity">



    <WebView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/webz"></WebView>
</android.support.constraint.ConstraintLayout>

这是我收到的错误信息

[ERROR:gl_surface_egl.cc(289)] eglChooseConfig failed with error EGL_SUCCESS

1
请按照此处建议的方式重新启动模拟器链接 - Usama Saeed US
我遇到了下一个错误 [ERROR:gl_surface_egl.cc(467)] eglChooseConfig 失败,错误代码为 EGL_SUCCESS。这是什么问题? - Miodrag Trajanovic
4个回答

2

尝试启用JavaScript并重写WebviewClient以避免重定向:

        WebView myWebview ;
        myWebview  = (WebView) this.findViewById(R.id.webz);
        myWebview.getSettings().setJavaScriptEnabled(true);
        myWebview.setWebViewClient(new WebViewClient());
        myWebview.loadUrl("https://en.wikipedia.org/");

并更新您的 WebView 的约束:

   <WebView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:id="@+id/webz"></WebView>

0

在你的 AndroidManifest.xml 文件中添加活动

android:name="com.(你的浏览器活动)" android:screenOrientation="portrait">


0
  1. 执行this操作
  2. 重启模拟器(如另一篇帖子和本帖评论中所建议的)
  3. 如果还不行,请重启设备。

对我有用。


0

问题可能出在模拟器的图形上,我相信。因为在模拟器上尝试@diegoveloper的解决方案仍然无法加载页面,但在实际的安卓设备上尝试成功了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接