Android利用可能なネットワークのチェック


後日調べるために転載する
private boolean CheckNetwork() {
       boolean flag = false;
       ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
       if (cwjManager.getActiveNetworkInfo() != null){
           flag = cwjManager.getActiveNetworkInfo().isAvailable();
       }
       if (!flag) {
           Builder b = new AlertDialog.Builder(this).setTitle("       ").setMessage("   GPRS WIFI    ");
           b.setPositiveButton("  ", 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");
                   startActivity(mIntent);
               }
           }).setNeutralButton("  ", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int whichButton) {
                   dialog.cancel();
               }
           }).create();
           b.show();
       }
       return flag;
   }