Wifi網(wǎng)卡狀態(tài)
10余年的冷水灘網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。營(yíng)銷型網(wǎng)站的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整冷水灘建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。成都創(chuàng)新互聯(lián)從事“冷水灘網(wǎng)站設(shè)計(jì)”,“冷水灘網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
WIFI_STATE_DISABLED Wifi網(wǎng)卡不可用
WIFI_STATE_DIABLING Wifi網(wǎng)卡正在關(guān)閉
WIFI_STATE_ENABLED Wifi網(wǎng)卡可用
WIFI_STATE_ENABLING Wifi網(wǎng)卡正在打開
WIFI_STATE_UNKNOWN 未知網(wǎng)卡狀態(tài)
操作Wifi網(wǎng)卡所需要的權(quán)限
CHANGE_NETWORK_STATE 改變網(wǎng)絡(luò)連接狀態(tài)
CHANGE_WIFI_STATE 改變Wifi連接狀態(tài)
ACCESS_NETWORK_STATE 允許應(yīng)用獲取網(wǎng)絡(luò)狀態(tài)信息
ACCESS_WIFI_STATE 允許應(yīng)用獲取Wifi狀態(tài)信息
界面activity_main.xml
需要的權(quán)限
MainActivity.java
public class MainActivity extends Activity { private Button startButton = null; private Button stopButton = null; private Button checkButton = null; private WifiManager wifiManager = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); startButton = (Button)findViewById(R.id.startWifi); stopButton = (Button)findViewById(R.id.stopWifi); checkButton = (Button)findViewById(R.id.checkWifi); startButton.setOnClickListener(new StartWifiListener()); stopButton.setOnClickListener(new StopWifiListener()); checkButton.setOnClickListener(new CheckWifiListener()); } class StartWifiListener implements OnClickListener{ @Override public void onClick(View v) { wifiManager = (WifiManager)MainActivity.this.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true); System.out.println("wifi state --->" + wifiManager.getWifiState()); Toast.makeText(MainActivity.this, "當(dāng)前Wifi網(wǎng)卡狀態(tài)為" + wifiManager.getWifiState(), Toast.LENGTH_SHORT).show(); } } class StopWifiListener implements OnClickListener{ @Override public void onClick(View arg0) { // TODO Auto-generated method stub wifiManager = (WifiManager)MainActivity.this.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(false); System.out.println("wifi state --->" + wifiManager.getWifiState()); /* getWifiState返回下面五個(gè)常量之一 下面的五個(gè)常量都是在WifiManager類中預(yù)定義的 public static final int WIFI_STATE_DISABLING = 0; public static final int WIFI_STATE_DISABLED = 1; public static final int WIFI_STATE_ENABLING = 2; public static final int WIFI_STATE_ENABLED = 3; public static final int WIFI_STATE_UNKNOWN = 4; */ Toast.makeText(MainActivity.this, "當(dāng)前Wifi網(wǎng)卡狀態(tài)為" + wifiManager.getWifiState(), Toast.LENGTH_SHORT).show(); } } class CheckWifiListener implements OnClickListener{ @Override public void onClick(View v) { wifiManager = (WifiManager)MainActivity.this.getSystemService(Context.WIFI_SERVICE); System.out.println("wifi state --->" + wifiManager.getWifiState()); Toast.makeText(MainActivity.this, "當(dāng)前Wifi網(wǎng)卡狀態(tài)為" + wifiManager.getWifiState(), Toast.LENGTH_SHORT).show(); } } }