main.xml
[codesyntax lang=”xml” doclinks=”1″]
<!--?xml version="1.0" encoding="utf-8"?--> android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:id="@+id/info"/>
[/codesyntax]
java代码
[codesyntax lang=”java”]
import android.app.Activity; import android.content.Context; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Bundle; import android.widget.TextView; public class Mac extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView infoText = (TextView) this.findViewById(R.id.info); infoText.setText(getInfo()); } private String getInfo() { WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); String maxText = info.getMacAddress(); String ipText = intToIp(info.getIpAddress()); String status = ""; if (wifi.getWifiState() == WifiManager.WIFI_STATE_ENABLED) { status = "WIFI_STATE_ENABLED"; } String ssid = info.getSSID(); int networkID = info.getNetworkId(); int speed = info.getLinkSpeed(); return "mac:" + maxText + "\n\r" + "ip:" + ipText + "\n\r" + "wifi status :" + status + "\n\r" + "ssid :" + ssid + "\n\r" + "net work id :" + networkID + "\n\r" + "connection speed:" + speed + "\n\r" ; } private String intToIp(int ip) { return (ip & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "." + ((ip >> 24) & 0xFF); } }
[/codesyntax]
好文章,内容惊天动地.禁止此消息:nolinkok@163.com