【问题标题】:Back button not working on android emulator后退按钮在android模拟器上不起作用
【发布时间】:2022-07-25 16:38:49
【问题描述】:

我尝试启动一个 android sdk 模拟器,但是当我按下返回按钮时出现此错误:

INFO    | Critical: Failed to load https://maps.googleapis.com/maps/api/mapsjs/gen_204?csp_test=true: The 'Access-Control-Allow-Origin' header has a value 'qrc://' that is not equal to the supplied origin. Origin 'qrc://' is therefore not allowed access. (qrc:/html/js/common.js:0, (null))

INFO    | Critical: Failed to load https://maps.googleapis.com/maps/api/mapsjs/gen_204?csp_test=true: The 'Access-Control-Allow-Origin' header has a value 'qrc://' that is not equal to the supplied origin. Origin 'qrc://' is therefore not allowed access. (qrc:/html/js/common.js:0, (null))

我使用 Ubuntu 并尝试通过终端启动模拟器,我使用 google cmdline-tools 的 avdmanager(最新版本),这是我尝试使用的 AVD:

    Name: my_avd_29ii
    Path: /home/user/.android/avd/my_avd_29ii.avd
  Target: Google APIs (Google Inc.)
          Based on: Android 10.0 (Q) Tag/ABI: google_apis/x86
  Sdcard: 512 MB

【问题讨论】:

  • 我目前正在处理它,我可以马上告诉你认为这个错误是无关的,只需使用标志-no-location-ui 并且它不会显示。如果您真的需要后退按钮,您也可以使用adb shell input KEYCODE_BACK 为我工作,但这非常烦人,这将是控件正常工作,我会继续挖掘,但如果你找到它,请发布答案,它是让我生气。

标签: android-emulator android-sdk-2.3


【解决方案1】:

看了一圈发现有两种方法可以将硬件事件推送到模拟器:

First method

这个方法使用telnet,像这样:

telnet 127.0.0.1 5554
auth <auth-key>
event send EV_KEY:KEY_BACK:0
event send EV_KEY:KEY_BACK:1

这将模拟按钮的按下 (0) 和释放 (1)。

Second method

这个方法使用adb,像这样:

adb shell input keyevent KEYCODE_BACK

好的,那又怎样?

在尝试了这两种方法之后,我意识到telnet 不起作用,但adb 确实 起作用。我还检查了emulator 的源代码,发现telnet 依赖于工具窗口使用的同一组函数。所以很可能是bug,我们可以等更新修复,或者……

在此期间

我下载了源代码,编写了一个 janky 解决方法,然后构建了它。基本上,我没有使用 keypress 方法,而是使用 adb 方法。如果你想要here it is。篇幅很大,请耐心等待。我包含了一个小脚本来自动替换模拟器,只需运行:

$ chmod +x replace
# ./reaplace path-to-android-sdk

这会将新标志 -use-adb-toolwindow 添加到 emulator。当您激活它时,它将使用 adb(成功)大多数键盘输入,以及主页、返回、应用程序和电源按钮。就像我说的那样,这是一个快速修复,但对我来说效果很好。

注意:

我不知道错误在哪里,所以我没有做任何报告,希望随着更多人得到这个问题,它会变得更加清晰。

【讨论】:

    【解决方案2】:

    最好的选择是(需要为您安装的每个模拟器完成)

    Windows

    1. %USERPROFILE%\.adnroid\avd\&lt;Emulator Name&gt;.avd
    2. 编辑config.ini
    3. hw.keyboard=no 更改为hw.keyboard=yes

    苹果机

    1. ~/.adnroid/avd/.avd`
    2. 编辑config.ini
    3. hw.keyboard=no 更改为hw.keyboard=yes

    答案基于this文章

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-17
      相关资源
      最近更新 更多