ChandreshKanetiya
ChandreshKanetiya

Reputation: 2414

How to disable captive network assistant into android device?

When a user connects to an open WiFi with a Captive Portal, the Android device will open a browser instance with the captive portal/login page.

We want to disable it, since we used an app for login purposes.

I came across the CaptivePortal Class into Android Marshmallow. Can I use it to disable network?

Class Name: android.net.CaptivePortal

Method Name: ignoreNetwork

How can I use the above class and method to disable auto launch of captive portal on WiFi?

Upvotes: 5

Views: 1894

Answers (1)

顏子鈞
顏子鈞

Reputation: 21

try this:

private void CaptivePortalDetectionEnabled() {
    if (CaptiveChange.isChecked()) {
        Settings.Global.putInt(MainActivity.this.getContentResolver(), "captive_portal_detection_enabled", 1);
        Toast.makeText(MainActivity.this, "Captive portal detection is now " + state() + "\n 網路檢查服務已\"開啟\"", Toast.LENGTH_SHORT).show();
    } else {
        Settings.Global.putInt(MainActivity.this.getContentResolver(), "captive_portal_detection_enabled", 0);
        Toast.makeText(MainActivity.this, "Captive portal detection is now " + state() + "\n 網路檢查服務已\"關閉\"", Toast.LENGTH_SHORT).show();
    }
}

Upvotes: 0

Related Questions