ANDROID: if WiFi is enabled AND active, launch an intent

前端 未结 5 1811
青春惊慌失措
青春惊慌失措 2020-12-13 03:15

This is what I would like to do :

=> IF WiFi is enabled AND active, launch an intent (in fact it\'s a WebView that gets its content=>the instructions of my app on th

5条回答
  •  难免孤独
    2020-12-13 03:28

    You can do it as follows:

      @Override
      public void onReceive(Context context, Intent intent) {
    
      String action = intent.getAction();
    
            if(WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)){
    
             Log.d("WIFI", "WIFI has changed");
             int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, -1);
             Log.d("WIFI", "WIFI State = " + wifiState);
             setCurrentWifiState(wifiState);
    
             }  
    

    You will get 0,1,2,3 depending on which state the Wifi is in, so for example 2 is connecting, you can check the rest in the documents

提交回复
热议问题