当前位置: 代码迷 >> Android >> android判断网络是不是能用
  详细解决方案

android判断网络是不是能用

热度:82   发布时间:2016-05-01 16:00:56.0
android判断网络是否能用
 public boolean CheckNetwork() {		    		    boolean flag = false;		    ConnectivityManager cwjManager = (ConnectivityManager) AndroidBaseActivity.self.getSystemService(Context.CONNECTIVITY_SERVICE);		    if (cwjManager.getActiveNetworkInfo() != null)		        flag = cwjManager.getActiveNetworkInfo().isAvailable();		    if (!flag) {		        Builder b = new AlertDialog.Builder( AndroidBaseActivity.self).setTitle("没有可用的网络").setMessage( AndroidBaseActivity.self.getResources().getString(R.string.net_work_message));		        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");		                AndroidBaseActivity.self.startActivity(mIntent);		            }		        }).setNeutralButton("取消", new DialogInterface.OnClickListener() {		            public void onClick(DialogInterface dialog, int whichButton) {		                dialog.cancel();		            }		        }).create();		        b.show();		    }		    Toast.makeText(AndroidBaseActivity.self, "test", 1).show();		   return flag;		}

?

  相关解决方案