/**  * 检测当前网络状态是否可用  *   * @return  */ public boolean checkNet() {  ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);  State mobile = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)    .getState();  State wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)    .getState();  // 移动网络  if (mobile == State.CONNECTED || mobile == State.CONNECTING)   return true;  // wifi网络  if (wifi == State.CONNECTED || wifi == State.CONNECTING)   return true;  return false; } @Override protected void onResume() {  super.onResume();  // 3秒后界面消失 } /**  * 网络不可用  进行网络设置  */ private void netWorkStatus() {  AlertDialog.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); // 如果在设置完成后需要再次进行操作,可以重写操作代码,在这里不再重写    finish();   }  }).setNeutralButton("否", new DialogInterface.OnClickListener() {   public void onClick(DialogInterface dialog, int whichButton) {    dialog.cancel();    System.exit(0);   }  }).show(); }

更多相关文章

  1. [ 转]Android 监控网络状态
  2. 操作Android 手机通讯录数据库
  3. Android:网络编程
  4. Android通知栏图标显示网络图片
  5. android 网络异步加载
  6. android 监听EditText 复制粘贴等操作
  7. Android网络电话软件Sipdroid试用

随机推荐

  1. Android:EditText学习总结
  2. 3.EditText控件
  3. android Makefile
  4. Android(安卓)UI设计——EditText控件
  5. android:configChanges
  6. 初探Android
  7. android 快速入门之一 “Hello world”,以
  8. 在android的Browser中设置User Agent
  9. Android(安卓)-- java代码设置margin
  10. android UI小结(二)