简体   繁体   English

有什么方法可以直接进入 Android 中的“启用 USB 调试”页面?

[英]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?是否有直接转到“启用 USB 调试”切换的 Intent 或请求启用它的方法?

---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.但是,当它们全部重新刷新时,需要启用 usb 调试。

We're aware of how to do this via ADB but our use case requires using a traditional in Android approach.我们知道如何通过 ADB 执行此操作,但我们的用例需要使用传统的 Android 方法。

--- End Explanation --- 结束说明

Is it possible to open a dialog allowing the user to go directly to the Usb Debugging option?是否可以打开一个对话框,让用户直接进入 USB 调试选项?

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. 这是可以使用Intent打开的所有设置的列表 ,请注意,其中不包括USB调试。

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: 您可以获得的最接近的结果是使用ACTION_APPLICATION_DEVELOPMENT_SETTINGS更多信息 )打开开发设置(如问题的后半部分所述),该操作将执行以下操作:

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.我开始搜索负责设置中开发人员选项页面 UI 的源文件。 I found DevelopmentSettingsDashboardFragment.java which has the method handleQsTileLongPressActionIfAny .我发现DevelopmentSettingsDashboardFragment.java有方法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 ).在这个方法中,我看到它正在寻找一个带有ACTION_QS_TILE_PREFERENCES操作的意图和一个EXTRA_COMPONENT_NAME extra,它有一个 ComponentName 匹配设置包名称( getPackageName() = com.android.settings )和 tile 子类名称( DevelopmentTiles.WirelessDebugging.class.getName() = com.android.settings.development.qstile.DevelopmentTiles$WirelessDebugging ,参见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).在 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在最近的应用列表中,它显示为作为应用内的子活动运行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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