如何在Android中获取接入点名称?

时间:2010-09-22 22:24:53

标签: android

我想知道,我们如何从Android手机获取接入点名称。

谢谢, 萨纳。

编辑:

WifiManager mWiFiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo w = mWiFiManager.getConnectionInfo();
Toast.makeText(this, "APN Name = "+w.getSSID(), Toast.LENGTH_SHORT).show();

以上代码段用于当前活动的APN名称。

谢谢tdelev

1 个答案:

答案 0 :(得分:2)

我想你指的是WiFi接入点,所以这是你可以用来实现的代码:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mWiFiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

        registerReceiver(mWiFiBroadcastReceiver, intentFilter);
    }

   final BroadcastReceiver mWiFiBroadcastReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        mScanResults = mWiFiManager.getScanResults();
        StringBuilder sb = new StringBuilder();
        for (ScanResult sr : mScanResults) {
            sb.append("ACCESS POINT NAME: " + sr.SSID);
            sb.append("\n");
            sb.append("BSSID: " + sr.BSSID);
            sb.append("\n");
            sb.append("SIGNAL: " + sr.level);
            sb.append("\n");

        }
        String info = sb.toString();
    }

};

希望这有助于你。