5
對於iPhone我可以檢測到該應用程序是在模擬器上運行通過這樣做:Xamarin.Android檢測模擬器
var isSumlator = ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.SIMULATOR;
什麼是用於檢測Xamarin.Android模擬器最好的相同呢?
對於iPhone我可以檢測到該應用程序是在模擬器上運行通過這樣做:Xamarin.Android檢測模擬器
var isSumlator = ObjCRuntime.Runtime.Arch == ObjCRuntime.Arch.SIMULATOR;
什麼是用於檢測Xamarin.Android模擬器最好的相同呢?
這取決於你的,如果這僅僅是本地調試測試或如果你打算把它留在你的代碼最終用戶環境中的測試目標。
由於Android的世界是相當大的,這是基於我們在野外看到一個不斷髮展的方法:
public bool isEmulator(bool LicensedPlayers = false)
{
var detect = 0;
try
{
var teleManager = (TelephonyManager)GetSystemService(TelephonyService);
string networkOperator = "";
try
{
networkOperator = teleManager.NetworkOperator;
if (LicensedPlayers)
{
if ((teleManager.NetworkOperatorName == "T-Mobile") &&
(Build.Radio == "unknown") &&
(Build.Serial == "unknown") &&
(Build.Manufacturer == "samsung"))
{
D.WriteLine("BlueStacks (OS-X) Player");
detect += 1;
}
}
}
catch
{
networkOperator = "";
D.WriteLine("TelephonyService Exceptiion, custom emulator");
detect += 1;
}
if (networkOperator.Contains("Android"))
{
D.WriteLine("Google's Android Emulator");
detect += 1;
}
}
catch
{
D.WriteLine("TelephonyService not available, custom emulator");
detect += 1;
}
if (LicensedPlayers)
{
if (Build.Display.Contains("andy") || (Build.Hardware.Contains("andy")))
{
D.WriteLine("Andy Player");
detect += 1;
}
}
if (Build.Hardware.Contains("goldfish"))
{
D.WriteLine("Goldfish-based Emulator");
detect += 1;
}
if (Build.Display.ToLowerInvariant().Contains("xamarin"))
{
D.WriteLine("Xamarin Android Player");
detect += 1;
}
if (Build.Hardware.Contains("vsemu"))
{
D.WriteLine("Visual Studio Android Emulator");
detect += 1;
}
if (Build.Host.Contains("genymobile") || (Build.Manufacturer.ToLowerInvariant().Contains("genymotion")))
{
D.WriteLine("Genymotion Android Emulator");
detect += 1;
}
if (Build.Hardware.Contains("vbox") && Build.Hardware.Contains("86"))
{
D.WriteLine("VirtualBox-based Emulator");
detect += 1;
}
return detect > 0;
}
更新:在多個平臺上
固定XAP模擬器檢測string fing = Build.Fingerprint;
bool isEmulator=false;
if (fing != null) {
isEmulator = fing.Contains("vbox") || fing.Contains("generic") || fing.Contains("vsemu");
}
僅供參考:許多手機(基於中國和CyanogenMod的版本)在其指紋中包含「通用」。 – SushiHangover