简体   繁体   中英

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?

我认为没有办法做到这一点,对于开发人员来说,此选项必须由您自己启用,而不是通过编码来启用

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.

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

带有示例代码的测试应用程序的主页快捷方式

  • App launched, wireless debugging settings page shown

启动应用程序,显示无线调试设置页面

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

在最近的应用列表中,它显示为作为应用内的子活动运行

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM