Last active
August 29, 2015 14:05
-
-
Save SZooo/fecdd7945b4cb86e35c2 to your computer and use it in GitHub Desktop.
wifi管理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WifiActivity extends Activity { | |
/** Called when the activity is first created. */ | |
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.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)WifiActivity.this.getSystemService(Context.WIFI_SERVICE); | |
wifiManager.setWifiEnabled(true); | |
System.out.println("wifi state --->" + wifiManager.getWifiState()); | |
Toast.makeText(WifiActivity.this, "当前Wifi网卡状态为" + wifiManager.getWifiState(), Toast.LENGTH_SHORT).show(); | |
} | |
} | |
class StopWifiListener implements OnClickListener{ | |
@Override | |
public void onClick(View arg0) { | |
// TODO Auto-generated method stub | |
wifiManager = (WifiManager)WifiActivity.this.getSystemService(Context.WIFI_SERVICE); | |
wifiManager.setWifiEnabled(false); | |
System.out.println("wifi state --->" + wifiManager.getWifiState()); | |
Toast.makeText(WifiActivity.this, "当前Wifi网卡状态为" + wifiManager.getWifiState(), Toast.LENGTH_SHORT).show(); | |
} | |
} | |
class CheckWifiListener implements OnClickListener{ | |
@Override | |
public void onClick(View v) { | |
wifiManager = (WifiManager)WifiActivity.this.getSystemService(Context.WIFI_SERVICE); | |
System.out.println("wifi state --->" + wifiManager.getWifiState()); | |
Toast.makeText(WifiActivity.this, "当前Wifi网卡状态为" + wifiManager.getWifiState(), Toast.LENGTH_SHORT).show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment