Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何自动化用户对Android用户权限对话框的响应?_Android_Android Intent_Ui Automation_Android Permissions_Android Bluetooth - Fatal编程技术网

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

如何自动化用户对Android用户权限对话框的响应?,android,android-intent,ui-automation,android-permissions,android-bluetooth,Android,Android Intent,Ui Automation,Android Permissions,Android Bluetooth,我正在编写一个在Android设备上运行蓝牙的测试应用程序。我希望我的测试应用程序能够使设备可发现。简单的搜索可以让我找到如下内容: Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300); startActivity(dis

我正在编写一个在Android设备上运行蓝牙的测试应用程序。我希望我的测试应用程序能够使设备可发现。简单的搜索可以让我找到如下内容:

Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
此方法的问题是,它将带来“用户权限”对话框


如何在“权限”对话框中自动按“是”或“否”?

嗯,我有类似的经验,下面是我的建议

  • 如果此权限对话框是由您的应用程序创建的,则您只需使用Espresso查找带有以下代码的“是”按钮

    onView(allOf(withText("Yes"), withParent(/* The features of the dialog */))).perform(click());
    
  • 如果此对话框不属于您的应用程序,则您必须使用UIAutomator。


  • 您是否在清单中声明了权限?只是想确定一下。我从未在我的应用程序中使用过蓝牙。我确实拥有所有的BT权限
    那么蓝牙呢?这允许您在无需用户交互的情况下配对蓝牙设备。这是一项安全功能。您可能找不到在非根设备上绕过它的方法。BLUETOOTH\u PRIVILEGED将允许您访问非公共API。你知道一个非公开的API来改变设备的可发现性吗?据我所知,公共API中没有。