【问题标题】:Android App not connecting to internet on emulatorAndroid App无法在模拟器上连接到互联网
【发布时间】:2018-06-11 18:40:50
【问题描述】:

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

<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/");

    }

}

这是我的主要活动

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

【问题讨论】:

  • 按照这里的建议重启模拟器link
  • 我有下一个错误 [ERROR:gl_surface_egl.cc(467)] eglChooseConfig 因错误 EGL_SUCCESS 失败。有什么问题?

标签: android network-connection


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:
      1. this
      2. 重启模拟器(在另一篇文章和这篇文章的 cmets 中建议)
      3. 如果这不起作用,请重新启动您的设备。

      为我工作。

      【讨论】:

        猜你喜欢
        • 2011-11-07
        • 2011-07-29
        • 1970-01-01
        • 1970-01-01
        • 2012-07-06
        • 1970-01-01
        • 1970-01-01
        • 2011-07-14
        • 1970-01-01
        相关资源
        最近更新 更多