android检测网络连接状态示例讲解

2019-12-10 20:08:14王旭

        } else {  
            AlertDialog.Builder builder = new AlertDialog.Builder(MoreGamesActivity.this);  
            builder.setTitle("没有可用的网络").setMessage("是否对网络进行设置?");  

            builder.setPositiveButton("是", new DialogInterface.OnClickListener() {  
                @Override  
                public void onClick(DialogInterface dialog, int which) {  
                    Intent intent = null;  

                    try {  
                        String sdkVersion = android.os.Build.VERSION.SDK;  
                        if(Integer.valueOf(sdkVersion) > 10) {  
                            intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);  
                        }else {  
                            intent = new Intent();  
                            ComponentName comp = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");  
                            intent.setComponent(comp);  
                            intent.setAction("android.intent.action.VIEW");  
                        }