我们如何在启用调试的 Android 6.0 设备上更轻松地打开 MTP?

How do we toggle on MTP more easily on a Debug-Enabled Android 6.0 device?

在 Android 6.0 中,MTP no longer works automatically:

Device connections through the USB port are now set to charge-only mode by default. To access the device and its content over a USB connection, users must explicitly grant permission for such interactions. If your app supports user interactions with the device over a USB port, take into consideration that the interaction must be explicitly enabled.

MTP 至少在每次插入 USB 数据线时都需要重新授权,并且可能比这更频繁(超时?)。

在启用 USB 调试的情况下,我发现让 MTP 共享在设备上工作的唯一解决方案是:

当您尝试使用外部存储设备上的文件时,这令人恼火

除了编写 UIAutomator "test" 来自动执行上述过程之外,是否有命令行方式让 MTP 运行?或者,有没有其他方法可以让 MTP 在没有这种准备过程的情况下工作?

在 Marshmallow(6.0 和 6.0.1)中,没有某种超能力是不可能的:-(

adb shell svc usb setFunction mtp

抛出 java.lang.SecurityException: Neither user 2000 nor current process has android.permission.MANAGE_USB. 并且 MANAGE_USBsignature|privileged 权限。我将其归档为 issue#193062。它已进入状态 Assigned 并标记为 Defect-25596495。它已在 N 开发者预览版中修复。