简体   繁体   English

如何在开发人员选项中仅具有“选择模拟位置应用”选项的电话中让模拟位置在android studio中工作?

[英]How to get mock locations to work in android studio for phones that only have “Select mock location app” option in Developer Options?

In Developer Options, the newer versions of Android at some point went from "Turn on Mock Locations" to "Select mock location app" option. 在开发人员选项中,较新版本的Android有时从“打开模拟位置”变为“选择模拟位置应用”选项。 The problem is that I want to be able to send it mock locations inside android studio in "Location" under "Extended Controls" where you can set Longitude and Latitude and even send a GPS data playback. 问题是我希望能够在android studio中的“扩展控件”下的“位置”中向其发送模拟位置,您可以在其中设置经度和纬度,甚至可以发送GPS数据回放。

But there is no "Turn on Mock Locations" option for these newer android versions. 但是这些较新的android版本没有“打开模拟位置”选项。 They all only have one option "Select mock location app". 它们都只有一个选项“选择模拟位置应用”。 But I don't want to use a mock location app installed on the emulator phone. 但是我不想使用模拟器电话上安装的模拟位置应用。 I want to send it mock locations inside the android studio itself. 我想将其发送到android studio内部的模拟位置。 How do I achieve this? 我该如何实现?

  1. Add entry to your manifest / debug manifest for testing: 在清单/调试清单中添加条目以进行测试:

    \nuses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" 使用权限android:name =“ android.permission.ACCESS_MOCK_LOCATION”\n
  2. Run your app on your device / emulator to get it installed. 在设备/仿真器上运行您的应用以进行安装。

It will fail but now it will also be listed in 'Select mock location app'. 它会失败,但现在也会列在“选择模拟位置应用”中。 Select it and then you should be able to do whatever you need. 选择它,然后您将能够执行所需的任何操作。

Edit: If you are running InstrumentationTest make sure you have added your app Location permission in the Application Settings because since API 22 it requires user consent AND manifest entry. 编辑:如果您正在运行InstrumentationTest,请确保已在“应用程序设置”中添加了应用程序“位置”权限,因为自API 22起,它需要用户同意和清单输入。

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

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