如果您禁用3G(单击F8),仍然可以使用浏览器而不会出现任何问题。我希望我的应用程序也有类似的功能,那么我该如何在我的应用程序中实现呢?
目前我们的应用程序中使用以下代码:
目前我们的应用程序中使用以下代码:
protected boolean isNetworkCoverageAvailable()
{
boolean result = false;
Context oContext = AndroidContext.getContext();
ConnectivityManager connMgr = (ConnectivityManager) oContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if(wifi.isConnected() == true){
result = true;
} else if (mobile.isConnectedOrConnecting() == true){
result = true;
} else {
result = oMgr.getDataState() == TelephonyManager.DATA_CONNECTED;
}
Log.d(TAG, "Result: " + result + "");
return result;
}
这个应用程序可以在Wi-Fi和3G网络下使用,但是如果设备无法使用3G,我希望应用程序能够自动激活3G。
在安卓系统中,我该如何实现这个功能?