首页 > 其他 > 详细

判断网络状态

时间:2015-12-08 15:59:59      阅读:199      评论:0      收藏:0      [点我收藏+]

<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />

private boolean getNetWorkStatus() {

boolean netSataus = false;
ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

cwjManager.getActiveNetworkInfo();

if (cwjManager.getActiveNetworkInfo() != null) {
  netSataus = cwjManager.getActiveNetworkInfo().isAvailable();
}

if (!netSataus) {
  Builder b = new AlertDialog.Builder(this).setTitle("没有可用的网络")
                      .setMessage("是否对网络进行设置?");
                      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");
                              startActivityForResult(mIntent,0);
                          }
                          }).setNeutralButton("否", new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int whichButton) {
                                  dialog.cancel();
                              }
                       }).show();
  }

              return netSataus;
}

判断网络状态

原文:http://www.cnblogs.com/bravolove/p/5029330.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!