(三十二)工具方法:如何判断是否有网络/如何调用系统设置界面
(1)如何判断是否有网络
/** * 判断是否有网络 * @return */ private boolean isNetWorkConnected(Context ctx) { // TODO Auto-generated method stub ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); Boolean result = false; if (info != null && info.isConnected()) { result = true; } else { result = false; } return result; }
(2)/如何调用系统设置界面
/** * * 方法一:进入系统设置界面 * */ private void setSystemSetting1() { Intent intent = null; if(android.os.Build.VERSION.SDK_INT>10){ intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); }else{ intent = new Intent(); ComponentName component = new ComponentName("com.android.settings","com.android.settings.WirelessSettings"); intent.setComponent(component); intent.setAction("android.intent.action.VIEW"); } startActivity(intent); }
/**
方法2:进入系统设置界面
*/
public void setSystemSetting2() {
// 点击网络设置按钮,进入系统设置
Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}