/** * 判断当前是否有网络 * @param context Activity的this * @return */ public static boolean CheckNetwork( final Context context) { boolean flag = false; ConnectivityManager cwjManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cwjManager.getActiveNetworkInfo() != null) flag = cwjManager.getActiveNetworkInfo().isAvailable(); if (!flag) { Builder b = new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.connectionError)).setMessage(context.getString(R.string.openConnectionHint)); b.setPositiveButton(context.getResources().getString(R.string.ensure), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Intent mIntent = new Intent("/"); ComponentName comp = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings"); mIntent.setComponent(comp); mIntent.setAction("android.intent.action.VIEW"); context.startActivity(mIntent); } }).setNeutralButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).create(); b.show(); } return flag; }