gpt4 book ai didi

android - 如何自动化用户对 Android 用户权限对话框的响应?

转载 作者:太空狗 更新时间:2023-10-29 14:17:05 25 4
gpt4 key购买 nike

我正在编写一个在 Android 设备上使用蓝牙的测试应用程序。我希望我的测试应用程序能够使设备可被发现。简单的搜索让我找到这样的东西:

Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);

这个方法的问题是它会带来用户权限对话框。 See here

如何在权限对话框中自动按 YES 或 NO?

最佳答案

嗯,我也有类似的经历,这是我的建议

  1. 如果此权限对话框是由您的应用程序创建的,那么您只需使用 Espresso 即可使用以下代码找到"is"按钮

    onView(allOf(withText("Yes"), withParent(/* The features of the dialog */))).perform(click());
  2. 如果这个对话框不属于您的应用程序,那么您必须使用 UIAutomator。
    Android Marshmallow: Test permissions with Espresso?

关于android - 如何自动化用户对 Android 用户权限对话框的响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20962490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com