Android应用未在模拟器上连接到互联网

时间:2018-01-02 01:05:04

标签: android network-connection

该应用无法连接到互联网。我有

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

在我的清单中,我检查了模拟器上的其他应用程序,例如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/");

    }

}

这是我的主要活动

<?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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

问题在于模拟器的图形我相信在模拟器上尝试@diegoveloper的解决方案仍然没有加载页面但是在实际的Android设备上尝试它是成功的。