我已经写了一个快速的android添加来显示连接到的wifi网络的SSID以及设备的IP地址。代码是:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Context context = getApplicationContext();
WifiManager wifi_man = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
if(wifi_man.isWifiEnabled()==true)
{
System.out.println("inwifi");
WifiInfo wifi_info = wifi_man.getConnectionInfo();
String ssid_name = wifi_info.getSSID();
TextView temp = (TextView)findViewById(R.id.widget40);
CharSequence sentence = "SSID NAME : "+ssid_name;
temp.setText(sentence);
int temp2 = wifi_info.getIpAddress();
String ip_addr = Formatter.formatIpAddress(temp2);
temp = (TextView)findViewById(R.id.widget41);
CharSequence sent = "IP ADDRESS : "+ip_addr;
temp.setText(sent);
}
}
然而,应用程序进程一旦启动就会崩溃...任何想法为什么。我也很困惑我的代码的入口点。我只是将我的应用代码放在onCreate流程的末尾吗?
答案 0 :(得分:1)
所以,正如我在评论中猜到的那样,你在清单中错过了这一行:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />