androidadbwifiadbwireless

detect wireless debugging option active or not in developer mode in android programmatically


I have tried developer mode and USB debugging is enabled or not. Using the below code changes. it's working fine.

private fun check_My_Android_Mobile_Developer_Mode_Status() {

// solution 1

val adb: Int = Settings.Secure.getInt(this.contentResolver,
            Settings.Global.ADB_ENABLED, 0)

        Toast.makeText(this,"USB Debugging Detect: adb mode:"+adb, Toast.LENGTH_LONG).show()

// solution 2

        if(Settings.Secure.getInt(this.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1) {
            // Developer Mode enabled
            Toast.makeText(this,"Developer Mode enabled: Show Alert", Toast.LENGTH_LONG).show()
        } else {
            //Developer Mode does not enabled
            Toast.makeText(this,"Developer does not enabled: Running Safe Mode", Toast.LENGTH_LONG).show()
        }
    }

But, I want to check wireless debug mode is enabled or not alone(from developer mode On status). I unable to find any solution.

Referred links below:

how-to-check-usb-debugging-enabled

wireless-adb-android-11

android-detect-when-adb-active-over-usb


Solution

  • Android source code reveals the wifi debugging setting: https://cs.android.com/android/platform/superproject/+/master:packages/apps/Settings/src/com/android/settings/development/WirelessDebuggingEnabler.java;l=73?q=wireless%20debugging

    Settings.Global.ADB_WIFI_ENABLED = "adb_wifi_enabled"

    fun isWifiAdbEnabled(): Boolean {
        // "this" is your activity or context
        return Settings.Global.getInt(this.contentResolver, "adb_wifi_enabled", 0) != 0
    }
    

    Usage:

    Toast.makeText(this, "adb mode: ${isWifiAdbEnabled()}", Toast.LENGTH_LONG).show()