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?
我认为没有办法做到这一点,对于开发人员来说,此选项必须由您自己启用,而不是通过编码来启用
No, it is not possible I'm afraid.
Here is a list of all Settings that can be opened with an Intent , note that USB debugging is not among them.
The closest you can get is opening up development settings (as the 2nd half of your question asked) with ACTION_APPLICATION_DEVELOPMENT_SETTINGS
( more info ), which does the following:
Activity Action: Show settings to allow configuration of application development-related settings.
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.
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
).
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();
}
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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.