当 运行 我的应用程序来自 Android Studio 时,我可以强制模拟器到顶部吗?
When running my App from Android Studio can I force the emulator to the top?
这是一个非常小的不便,但我希望当我从 Android Studio 开始 运行 我的应用程序时,Android 模拟器弹出到前面。
我知道模拟器中的 "Always on Top" 设置,但我在处理代码时必须将模拟器最小化。 运行 我的应用没有恢复模拟器。
我已经尝试这样做一段时间了...我想这不可能完成。
我通过购买另一台显示器并将模拟器推到另一台显示器来解决问题。
为我的问题创建了一个解决方案 - 我正在开发 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
如果一切正常(并且模拟器是 运行ning),它将弹出到前面。
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)
运行 您的应用程序并观看模拟器弹出到最前面!
遵循@Ves 接受的答案确实有效但更改了批处理文件,因为它对我不起作用,这是我编辑批处理文件的方式 BringProcessToFront。ps1 基于另一个答案 https://superuser.com/questions/647216/startup-program-bring-to-foreground.
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)
然后我按照接受的答案中的其余步骤进行操作,结果成功了。
我为此使用 AutoHotkey 和一个非常简单的脚本:
#IfWinActive, ahk_class SunAwtFrame
$+F10::
Send, +{F10}
WinActivate, Android Emulator
return
此 运行 应用程序并在您按 F10 时激活上次使用的模拟器
您也可以编译并使用它 运行 而无需安装 AutoHotkey。
这是一个非常小的不便,但我希望当我从 Android Studio 开始 运行 我的应用程序时,Android 模拟器弹出到前面。
我知道模拟器中的 "Always on Top" 设置,但我在处理代码时必须将模拟器最小化。 运行 我的应用没有恢复模拟器。
我已经尝试这样做一段时间了...我想这不可能完成。
我通过购买另一台显示器并将模拟器推到另一台显示器来解决问题。
为我的问题创建了一个解决方案 - 我正在开发 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 如果一切正常(并且模拟器是 运行ning),它将弹出到前面。
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)
运行 您的应用程序并观看模拟器弹出到最前面!
遵循@Ves 接受的答案确实有效但更改了批处理文件,因为它对我不起作用,这是我编辑批处理文件的方式 BringProcessToFront。ps1 基于另一个答案 https://superuser.com/questions/647216/startup-program-bring-to-foreground.
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)
然后我按照接受的答案中的其余步骤进行操作,结果成功了。
我为此使用 AutoHotkey 和一个非常简单的脚本:
#IfWinActive, ahk_class SunAwtFrame
$+F10::
Send, +{F10}
WinActivate, Android Emulator
return
此 运行 应用程序并在您按 F10 时激活上次使用的模拟器
您也可以编译并使用它 运行 而无需安装 AutoHotkey。