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

前端 未结 5 1804
青春惊慌失措
青春惊慌失措 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:24

    In your BroadcastReceiver class:

    @Override
    public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
        if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)){                
            boolean connected = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false);
            if (connected){
                // start your service here
            }
        }                   
    }
    

    And in your AndroidManifest.xml make sure you register for the android.net.wifi.supplicant.CONNECTION_CHANGE broadcast intent.

        
        
    
    

提交回复
热议问题