码迷,mamicode.com
首页 > 移动开发 > 详细

android判断网络状态

时间:2014-11-11 14:24:19      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:android

<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;  
   }  

android判断网络状态

标签:android

原文地址:http://blog.csdn.net/u014600432/article/details/41010713

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!