Android wifiオープン
詳細
MainActivity.java
manifest.xml com.wifi.01.rar (685.1 KB) ダウンロード回数:0
MainActivity.java
package com.wifi;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.Menu;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
public class MainActivity extends Activity {
private List list=new ArrayList();
private WifiManager manager;
private WifiInfo info;
private CheckBox checkBox;
private TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkBox=(CheckBox) findViewById(R.id.checkBox1);
textView=(TextView) findViewById(R.id.textView1);
manager=(WifiManager) getSystemService(Context.WIFI_SERVICE);
if(manager.isWifiEnabled()){
checkBox.setChecked(true);
textView.setText("WiFi ");
}else{
checkBox.setChecked(false);
textView.setText("WiFi ");
}
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked==false){
manager.setWifiEnabled(false);
textView.setText(" WiFi");
}else{
manager.setWifiEnabled(true);
list=manager.getConfiguredNetworks();
if(list!=null&&list.size()>0){
int networkid=list.get(0).networkId;
manager.enableNetwork(networkid, true);
textView.setText(" wifi");
}else{
textView.setText(" wifi");
}
}
}
});
}
}
manifest.xml