我正在尝试在Android Studio上运行NetworkUsage示例项目应用程序。我从NetworkUsage.zip下载了该项目并将其导入Android Studio。该项目构建没有问题,但是当它在模拟器上运行时,但最终在UI中显示消息:" Lost Connection"然后是"无法加载内容。检查您的网络连接"。
在跟踪执行时,我看到当调用onStart()时,它会调用updateConnectedFlags()。在这种方法中,
activeInfo != null && activeInfo.isConnected()
是一个真实的陈述,但执行:
wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
导致wifiConnected = false且mobileConnected为true。由于这是一个运行的模拟器,因此mobileConnected确实有点奇怪。之后,调用类NetworkReceiver中的onReceive()方法,但以下语句失败:
if (WIFI.equals(sPref) && networkInfo != null
&& networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
因为networkInfo.getType()= 0且ConnectivityManager.TYPE_WIFI = 1(networkInfo不为null且sPref = WIFI)。这导致"失去连接"。
我在运行项目时看到的唯一运行时错误是:
03-14 11:28:36.078 2918-2918/com.example.android.networkusage W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
03-14 11:28:36.227 2918-2939/com.example.android.networkusage W/AudioManagerAndroid﹕ Requires BLUETOOTH permission
03-14 11:28:36.211 2918-2918/com.example.android.networkusage W/chromium﹕ [WARNING:resource_bundle.cc(315)] locale_file_path.empty()
03-14 11:28:36.267 2918-2918/com.example.android.networkusage I/chromium﹕ [INFO:aw_browser_main_parts.cc(63)] Load from apk succesful, fd=32 off=46092 len=2953
03-14 11:28:36.269 2918-2918/com.example.android.networkusage I/chromium﹕ [INFO:aw_browser_main_parts.cc(78)] Loading webviewchromium.pak from, fd:33 off:228796 len:643667
03-14 11:28:36.404 2918-2918/com.example.android.networkusage E/chromium﹕ [ERROR:gl_surface_egl.cc(150)] No suitable EGL configs found.
03-14 11:28:36.404 2918-2918/com.example.android.networkusage E/chromium﹕ [ERROR:gl_surface_android.cc(23)] GLSurfaceEGL::InitializeOneOff failed.
03-14 11:28:36.404 2918-2918/com.example.android.networkusage E/chromium﹕ [ERROR:browser_main_loop.cc(940)] GLSurface::InitializeOneOff failed
03-14 11:28:36.714 2918-2945/com.example.android.networkusage W/chromium﹕ [WARNING:proxy_service.cc(901)] PAC support disabled because there is no system implementation
03-14 11:28:36.750 2918-2918/com.example.android.networkusage W/chromium﹕ [WARNING:data_reduction_proxy_settings.cc(403)] SPDY proxy OFF at startup
03-14 11:28:36.910 2918-2918/com.example.android.networkusage W/art﹕ Attempt to remove local handle scope entry from IRT, ignoring
03-14 11:28:36.948 2918-2918/com.example.android.networkusage W/AwContents﹕ onDetachedFromWindow called when already detached. Ignoring
我在Mac上运行Android Studio。这个样本失败的原因可能是什么?有没有人有使用ConnectivityManager的经验,说wifi无法与模拟器一起使用?我想利用这个示例软件。