【发布时间】:2019-02-18 15:09:34
【问题描述】:
这是一个非常小的不便,但是当我开始从 Android Studio 运行我的应用程序时,我希望 Android 模拟器弹出到前面。
我知道模拟器中的“始终位于顶部”设置,但在处理代码时我必须最小化模拟器。运行我的应用程序不会恢复模拟器。
【问题讨论】:
标签: windows android-studio android-emulator
这是一个非常小的不便,但是当我开始从 Android Studio 运行我的应用程序时,我希望 Android 模拟器弹出到前面。
我知道模拟器中的“始终位于顶部”设置,但在处理代码时我必须最小化模拟器。运行我的应用程序不会恢复模拟器。
【问题讨论】:
标签: windows android-studio android-emulator
遵循@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)
然后我按照接受的答案中的其余步骤进行操作,并且成功了。
【讨论】:
为我的问题创建了一个解决方案 - 我正在 Windows 10 上进行开发。
创建一个 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)
确保您可以从命令行实际运行此脚本。默认安全性不允许您运行脚本,作为管理员,您需要允许它们使用 Set-Execution 如果一切正常(并且模拟器正在运行),它将弹出到前面。
powershell -command C:\users\username\BringProcessToFront.ps1
在 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)
运行您的应用程序并观看模拟器弹出到最前面!
【讨论】:
我为此使用AutoHotkey 和一个非常简单的脚本:
#IfWinActive, ahk_class SunAwtFrame
$+F10::
Send, +{F10}
WinActivate, Android Emulator
return
这会在您按 F10 时运行应用并激活上次使用的模拟器
您也可以在不安装 AutoHotkey 的情况下编译并运行它。
【讨论】:
我已经尝试这样做一段时间了......我想它无法完成。
我通过购买另一台显示器并将模拟器推到另一台显示器解决了这个问题。
【讨论】: