try the following:
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();
}
}