【问题标题】:When running my App from Android Studio can I force the emulator to the top?从 Android Studio 运行我的应用程序时,我可以强制模拟器到顶部吗?
【发布时间】:2019-02-18 15:09:34
【问题描述】:

这是一个非常小的不便,但是当我开始从 Android Studio 运行我的应用程序时,我希望 Android 模拟器弹出到前面。

我知道模拟器中的“始终位于顶部”设置,但在处理代码时我必须最小化模拟器。运行我的应用程序不会恢复模拟器。

【问题讨论】:

    标签: windows android-studio android-emulator


    【解决方案1】:

    遵循@Ves 接受的答案确实有效,但更改了批处理文件,因为它对我不起作用,这是我根据另一个答案编辑批处理文件 BringProcessToFront.ps1 的方法@ 987654321@.

    if ( $args ){
       $processName = $args[0]
    }
    else{
       $processName = "qemu-system-i386"
    }
    
    Add-Type @"
      using System;
      using System.Runtime.InteropServices;
      public class Tricks {
         [DllImport("user32.dll")]
         [return: MarshalAs(UnmanagedType.Bool)]
         public static extern bool SetForegroundWindow(IntPtr hWnd);
      }
    "@
    sleep -sec 1
    $h = (Get-Process $processName).MainWindowHandle
    [void] [Tricks]::SetForegroundWindow($h)
    

    然后我按照接受的答案中的其余步骤进行操作,并且成功了。

    【讨论】:

      【解决方案2】:

      为我的问题创建了一个解决方案 - 我正在 Windows 10 上进行开发。

      1. 创建一个 PowerShell 批处理文件 BringProcessToFront.ps1(*注意您的模拟器可能有不同的名称,例如 qemu-system-x86_64 *)

        if ( $args ){
           $processName = $args[0]
        }
        else{
           $processName = "qemu-system-i386"
        }
        
        $sig = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
        Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32
        $hwnd = @(Get-Process $processName)[0].MainWindowHandle
        [Win32.NativeMethods]::ShowWindowAsync($hwnd, 4)
        
      2. 确保您可以从命令行实际运行此脚本。默认安全性不允许您运行脚本,作为管理员,您需要允许它们使用 Set-Execution 如果一切正常(并且模拟器正在运行),它将弹出到前面。

        powershell -command C:\users\username\BringProcessToFront.ps1
        
      3. 在 Android Studio 中创建一个新的外部工具“BringEmulatorToFront”

        Run>Edit Configuraions
        Expand Android App and select app
        Before launch:  (Hit the green + sign to add a new external tool)
           In the "External Tools Dialog" hit the green + to create a new tool)
               Name: BringEmulatorToFront
               Description: Launch PowerShell to make sure Emulator is visible
               Program: powershell
               Arguments: -command C:\users\username\BringProcessToFront.ps1
               Working directory: C:\users\username
               *IMPORTANT*
                Uncheck the Advanced options Synchronize files and Open console
                (If you leave Open console checked your run will not terminate cleanly)           
        
      4. 运行您的应用程序并观看模拟器弹出到最前面!

      【讨论】:

        【解决方案3】:

        我为此使用AutoHotkey 和一个非常简单的脚本:

        #IfWinActive, ahk_class SunAwtFrame
        $+F10::
        Send, +{F10}
        WinActivate, Android Emulator
        return
        

        这会在您按 F10 时运行应用并激活上次使用的模拟器

        您也可以在不安装 AutoHotkey 的情况下编译并运行它。

        【讨论】:

          【解决方案4】:

          我已经尝试这样做一段时间了......我想它无法完成。

          我通过购买另一台显示器并将模拟器推到另一台显示器解决了这个问题。

          【讨论】:

          • 查看我的答案 - 了解如何在 Windows 上执行此操作。必须可以在所有平台上执行类似操作。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-02-12
          • 2021-12-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多