开发者

How to get the Access Point Name in Android?

开发者 https://www.devze.com 2023-01-17 01:10 出处:网络
I would like to know, how do we get the access point name from an Android Phone. Thanks, Sana. EDIT: WifiManager mWiFiManager = (WifiManager) getSystemService(Cont开发者_如何学编程ext.WIFI_SERVICE)

I would like to know, how do we get the access point name from an Android Phone.

Thanks, Sana.

EDIT:

WifiManager mWiFiManager = (WifiManager) getSystemService(Cont开发者_如何学编程ext.WIFI_SERVICE);
WifiInfo w = mWiFiManager.getConnectionInfo();
Toast.makeText(this, "APN Name = "+w.getSSID(), Toast.LENGTH_SHORT).show();

The above code snippet is for current active APN name.

Thanks tdelev


I suppose you are referring to a WiFi Access Point so this is the code you can use to achieve that:

    @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();
    }

};

Hope this helped you.

0

精彩评论

暂无评论...
验证码 换一张
取 消