您的位置:首页 > 服装鞋帽 > 休闲装 > WifiManager状态判断 part2

WifiManager状态判断 part2

luyued 发布于 2011-01-28 20:32   浏览 N 次  
  1. else if(mCheckBox01.isChecked()==true)
  2. {
  3. /* 尝试打开Wi-Fi服务 */
  4. try
  5. {
  6. /* 确认WiFi服务是关闭且不在打开操作中 */
  7. if(!mWiFiManager01.isWifiEnabled() &&
  8. mWiFiManager01.getWifiState()!=
  9. WifiManager.WIFI_STATE_ENABLING )
  10. {
  11. if(mWiFiManager01.setWifiEnabled(true))
  12. {
  13. switch(mWiFiManager01.getWifiState())
  14. {
  15. /* WiFi正在启动过程中,导致无法打开... */
  16. case WifiManager.WIFI_STATE_ENABLING:
  17. mTextView01.setText
  18. (
  19. getResources().getText
  20. (R.string.str_wifi_enabling)
  21. );
  22. break;
  23. /* WiFi已经为打开,无法再次打开... */
  24. case WifiManager.WIFI_STATE_ENABLED:
  25. mTextView01.setText
  26. (
  27. getResources().getText
  28. (R.string.str_start_wifi_done)
  29. );
  30. break;
  31. /* 其他未知的错误 */
  32. default:
  33. mTextView01.setText
  34. (
  35. getResources().getText
  36. (R.string.str_start_wifi_failed)+":"+
  37. getResources().getText
  38. (R.string.str_wifi_unknow)
  39. );
  40. break;
  41. }
  42. }
  43. else
  44. {
  45. mTextView01.setText(R.string.str_start_wifi_failed);
  46. }
  47. }
  48. else
  49. {
  50. switch(mWiFiManager01.getWifiState())
  51. {
  52. /* WiFi正在打开过程中,导致无法打开... */
  53. case WifiManager.WIFI_STATE_ENABLING:
  54. mTextView01.setText
  55. (
  56. getResources().getText
  57. (R.string.str_start_wifi_failed)+":"+
  58. getResources().getText
  59. (R.string.str_wifi_enabling)
  60. );
  61. break;
  62. /* WiFi正在关闭过程中,导致无法打开... */
  63. case WifiManager.WIFI_STATE_DISABLING:
  64. mTextView01.setText
  65. (
  66. getResources().getText
  67. (R.string.str_start_wifi_failed)+":"+
  68. getResources().getText
  69. (R.string.str_wifi_disabling)
  70. );
  71. break;
  72. /* WiFi已经关闭 */
  73. case WifiManager.WIFI_STATE_DISABLED:
  74. mTextView01.setText
  75. (
  76. getResources().getText
  77. (R.string.str_start_wifi_failed)+":"+
  78. getResources().getText
  79. (R.string.str_wifi_disabled)
  80. );
  81. break;
  82. /* 无法取得或识别WiFi状态 */
  83. case WifiManager.WIFI_STATE_UNKNOWN:
  84. default:
  85. mTextView01.setText
  86. (
  87. getResources().getText
  88. (R.string.str_start_wifi_failed)+":"+
  89. getResources().getText
  90. (R.string.str_wifi_unknow)
  91. );
  92. break;
  93. }
  94. }
  95. mCheckBox01.setText(R.string.str_uncheck);
  96. }
  97. catch (Exception e)
  98. {
  99. Log.i("HIPPO", e.toString());
  100. e.printStackTrace();
  101. }
  102. }
  103. }
  104. });
  105. }
  106. public void mMakeTextToast(String str, boolean isLong)
  107. {
  108. if(isLong==true)
  109. {
  110. Toast.makeText(EX05_17.this, str, Toast.LENGTH_LONG).show();
  111. }
  112. else
  113. {
  114. Toast.makeText(EX05_17.this, str, Toast.LENGTH_SHORT).show();
  115. }
  116. }
  117. @Override
  118. protected void onResume()
  119. {
  120. // TODO Auto-generated method stub
  121. /* 在onResume重写事件为取得打开程序当下WiFi的状态 */
  122. try
  123. {
  124. switch(mWiFiManager01.getWifiState())
  125. {
  126. /* WiFi已经在打开状态... */
  127. case WifiManager.WIFI_STATE_ENABLED:
  128. mTextView01.setText
  129. (
  130. getResources().getText(R.string.str_wifi_enabling)
  131. );
  132. break;
  133. /* WiFi正在打开过程中状态... */
  134. case WifiManager.WIFI_STATE_ENABLING:
  135. mTextView01.setText
  136. (
  137. getResources().getText(R.string.str_wifi_enabling)
  138. );
  139. break;
  140. /* WiFi正在关闭过程中... */
  141. case WifiManager.WIFI_STATE_DISABLING:
  142. mTextView01.setText
  143. (
  144. getResources().getText(R.string.str_wifi_disabling)
  145. );
  146. break;
  147. /* WiFi已经关闭 */
  148. case WifiManager.WIFI_STATE_DISABLED:
  149. mTextView01.setText
  150. (
  151. getResources().getText(R.string.str_wifi_disabled)
  152. );
  153. break;
  154. /* 无法取得或识别WiFi状态 */
  155. case WifiManager.WIFI_STATE_UNKNOWN:
  156. default:
  157. mTextView01.setText
  158. (
  159. getResources().getText(R.string.str_wifi_unknow)
  160. );
  161. break;
  162. }
  163. }
  164. catch(Exception e)
  165. {
  166. mTextView01.setText(e.toString());
  167. e.getStackTrace();
  168. }
  169. super.onResume();
  170. }
  171. @Override
  172. protected void onPause()
  173. {
  174. // TODO Auto-generated method stub
  175. super.onPause();
  176. }
  177. }

阅读全文
类别:Wifi 查看评论
图文资讯
广告赞助商