Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to go directly to the "Enable Usb Debugging" page in Android?

Is there an Intent that goes directly to the "Enable USB Debugging" toggle or a way to request it to be enabled?

---Situation Explanation---

We have an application we use for testing on many phones at once and they all have developer mode enabled. However, usb debugging needs to be enabled when they're all reflashed.

We're aware of how to do this via ADB but our use case requires using a traditional in Android approach.

--- End Explanation

Is it possible to open a dialog allowing the user to go directly to the Usb Debugging option?

Similarly, is it possible to do this with developer mode?

like image 250
EndOfAll Avatar asked Oct 31 '25 12:10

EndOfAll


1 Answers

Edit 1

handleQsTileLongPressActionIfAny was added in Android 12, so this only works in Android 12 and higher.

In the entire source for Android 11's Settings app there is no SubSettingLauncher with WirelessDebuggingFragment.class found, so an alternative solution is not possible.

Preface

Since there exist Quick Setting Tiles for Developer Options (which includes Wireless Debugging) and long press of one brings you to it's related page in Settings, I thought to figure out what intent it is sending and how to replicate it.

Observations

I started with searching for the source file responsible for the UI of the Developer Options page in Settings. I found DevelopmentSettingsDashboardFragment.java which has the method handleQsTileLongPressActionIfAny. In this method I saw that it is looking for an intent with the ACTION_QS_TILE_PREFERENCES action and an EXTRA_COMPONENT_NAME extra that has a ComponentName matching the Settings package name (getPackageName() = com.android.settings) and tile subclass name (DevelopmentTiles.WirelessDebugging.class.getName() = com.android.settings.development.qstile.DevelopmentTiles$WirelessDebugging, see DevelopmentTiles.java).

Example (Code)

From these observations, I wrote the following example code:

Intent intent = new Intent(TileService.ACTION_QS_TILE_PREFERENCES);
intent.putExtra(Intent.EXTRA_COMPONENT_NAME, new ComponentName("com.android.settings", "com.android.settings.development.qstile.DevelopmentTiles$WirelessDebugging"));
try {
    startActivity(intent);
    finish();
} catch (Exception e) {
    Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
    finish();
}

Testing Example (Images)

After testing it, it works perfectly. The Quick Settings Tile for Wirless Debugging doesn't even have to be enabled for it to work (though Developer Options does have to be enabled).

Tested on Android 13 (Google Pixel 7 Pro).

  • Home shortcut of test app with example code

Home shortcut of test app with example code

  • App launched, wireless debugging settings page shown

App launched, wireless debugging settings page shown

  • In recent app list, it is shown to be running as a subactivity within the app

In recent app list, it is shown to be running as a subactivity within the app

like image 198
xjonx Avatar answered Nov 02 '25 03:11

xjonx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!