How to get the name of currently connected WiFi network in Android with BroadcastReceiver [duplicate]

送分小仙女□ 提交于 2019-12-06 04:37:31

问题


In my implementation of BroadcastReceiver I want to run some Activity when user is connected to WiFi network with specific name. How can I do that? How can I get the Wifi network name in BroadcastReceiver? And how can I find out that this is wifi connection? Thank you!

I already has a code:

public class ConnectionChangeReceiver extends BroadcastReceiver
{
  @Override
  public void onReceive( Context context, Intent intent )
  {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY_SERVICE );
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(     ConnectivityManager.TYPE_MOBILE );
    if ( activeNetInfo != null )
    {

      Toast.makeText( context, "Active Network Type : " + activeNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show();
    }
    if( mobNetInfo != null )
    {
      Toast.makeText( context, "Mobile Network Type : " + mobNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show();
    }
  }
}

回答1:


Take a look at this ScanResult. The SSID field is the network name. You can use getScanResults() to get the latest scan results.



来源:https://stackoverflow.com/questions/7687808/how-to-get-the-name-of-currently-connected-wifi-network-in-android-with-broadcas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!