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

标签 android network-connection

该应用程序未连接到互联网。我有

<uses-permission android:name="android.permission.INTERNET" />

在我的 list 中,我检查了模拟器上的其他应用程序,例如 youtube 和谷歌搜索工作正常,但应用程序无法加载页面。这是我的主要 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/");

    }

}

这是我的主要 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

最佳答案

尝试启用 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>

关于Android 应用程序无法在模拟器上连接到互联网,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48054518/

相关文章:

android - Delphi XE5 Android - 屏幕分辨率和设备配置文件

ios - 检查具有可达性的网络连接 - IsWWAN 标志始终为 'false'

java - 如何使用loopj概念在android中以Json格式发送本地主机服务器上的当前纬度和经度数据?

android - 无法接收网络相关事件

powershell - 在 PowerShell 中,如何确定加入域的计算机是否连接到域网络?

android - AdapterView 的自动滚动(Listview,GridView,...)

android - 该类不能继承自AndroidViewModel,为什么?

android - 具有泛型和 Void/Nothing 返回类型的 Kotlin 结果类型

android - 按下后退按钮时如何用 fragment A替换 fragment C?