转载,以备日后查阅


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


更多相关文章

  1. Android: 判断网络状态
  2. 【原创】android webview 加载网络视频
  3. Android(安卓)分别使用Post与Get实现网络图片加载
  4. android如何获取经纬度
  5. android检查网络连接状态
  6. Android判断Intent是否存在,是否可用
  7. android 自动获取时间,网络提供的值
  8. 【简单的学生管理界面】Android的if语句中有字符串判断
  9. Android(安卓)的网络编程

随机推荐

  1. android 使用TextView/EditText应该注意
  2. TextView字间距和行间距设置
  3. 使用AIDL实现Android的跨进程通信
  4. android checkbox,radiobox style自定义
  5. Phone拨号调起InCallUi流程(Phone 9.0 )(P
  6. 基于Android(安卓)XML解析与保存的实现
  7. Android Drawable Importer的使用
  8. Android中判断字符串中必须包含字母或者
  9. android browser 的几个小feature (四) k
  10. Android SDK R17