次の例を使用しようとしています。
特定のネットワークを探すようにアンドロイドをプログラムするにはどうすればよいですか?
しかし、次の行に起因する問題のため、実行できません。
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
その後、他にもいくつかのエラーが発生しますが、チュートリアル/例に正確に従っていると思います。
import java.util.List;
import android.app.Activity;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.util.Log;
import android.content.Context;
public class Connect extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.connect);
String networkSSID = "ANDRE-PC_NETWORK";
String networkPass = "superman";
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\""; //ssid must be in quotes
conf.wepKeys[0] = "\"" + networkPass + "\"";
conf.wepTxKeyIndex = 0;
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
conf.preSharedKey = "\""+ networkPass +"\"";
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
wifiManager.addNetwork(conf);
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for( WifiConfiguration i : list ) {
if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
WifiManager.disconnect();
WifiManager.enableNetwork(i.networkId, true);
WifiManager.reconnect();
break;
}
}
}}
日食の問題ログの問題:
Description Resource Path Location Type
Cannot make a static reference to the non-static method reconnect() from the type WifiManager Connect.java line 41 Java Problem
Cannot make a static reference to the non-static method disconnect() from the type WifiManager Connect.java line 39 Java Problem
Cannot make a static reference to the non-static method enableNetwork(int, boolean) from the type WifiManager Connect.java line 40 Java Problem