tags:

views:

42

answers:

2

Hi,

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

Thanks, Sana.

EDIT:

WifiManager mWiFiManager = (WifiManager) getSystemService(Context.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

A: 

You just need to put this at the top of your java file:

import android.graphics.*;

or you could reference it directly by using

import android.graphics.Point;

Then just initialize it like you would any other class

Reference: http://developer.android.com/reference/android/graphics/Point.html

SilverLogic
+1  A: 

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.

tdelev
Does this give the Access Point Name which has is currently connected or does this give the APNs which are detectable? Do we use the getConnectionInfo() to get the current active connected APN?
Sana
Yes, this gives you all APNs that are discovered, so if you want to find out the current active connected APN you could use some other method (perhaps getConnectionInfo())
tdelev