最近有个需求,需要判断当前设备是否是模拟器,网上查了一下,发现基本上都是使用特征字符串进行检索,类似这种:
if (SystemInfo.deviceModel.Contains("Emulator") || SystemInfo.deviceModel.Contains("Android SDK"))
return true;
if (SystemInfo.deviceName.Contains("Android SDK"))//设备名称的字符串检测
return true;
if (SystemInfo.deviceType == DeviceType.Unknown && SystemInfo.operatingSystem.Contains("x86"))//当前设备的类型字符串检测
return true;
if (SystemInfo.processorType.Contains("Intel") || SystemInfo.processorType.Contains("AMD"))//当前设备的CPU类型检测
return true;
if (SystemInfo.graphicsDeviceName.Contains("Intel") || SystemInfo.graphicsDeviceName.Contains("VBox"))//当前设备的显卡名称检测
return true;
发现都是不行的,因为现在的模拟器都会伪装==
还有一种方法是使用AndroidJavaClass来调用安卓相关的方法:参考林新发大佬
例如这种:
ps:由于没用安卓相关开发知识,可能只是我写错了
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent", new object[] { });
intentObject.Call<AndroidJavaObject>("setData", new AndroidJavaObject("android.net.Uri", "tel:" + 123456));
测试了一下,都是没用成功。。。。
最后是在是没法了,只能打印所有的SystemInfo的静态字段查看有什么不同:
text2.text = "SystemInfo.batteryLevel" + ":" + SystemInfo.batteryLevel + "\n" +
"SystemInfo.deviceModel" + ":" + SystemInfo.deviceModel + "\n" +
"SystemInfo.batteryStatus" + ":" + SystemInfo.batteryStatus + "\n" +
"SystemInfo.constantBufferOffsetAlignment" + ":" + SystemInfo.constantBufferOffsetAlignment + "\n" +
"SystemInfo.copyTextureSupport" + ":" + SystemInfo.copyTextureSupport + "\n" +
"SystemInfo.deviceName" + ":" + SystemInfo.deviceName + "\n" +
"SystemInfo.deviceType" + ":" + SystemInfo.deviceType + "\n" +
"SystemInfo.deviceUniqueIdentifier" + ":" + SystemInfo.deviceUniqueIdentifier + "\n" +
"SystemInfo.graphicsDeviceID" + ":" + SystemInfo.graphicsDeviceID + "\n" +
"SystemInfo.graphicsDeviceName" + ":" + SystemInfo.graphicsDeviceName + "\n" +
"SystemInfo.graphicsDeviceType" + ":" + SystemInfo.graphicsDeviceType + "\n" +
"SystemInfo.graphicsDeviceVendor" + ":" + SystemInfo.graphicsDeviceVendor + "\n" +
"SystemInfo.graphicsDeviceVendorID" + ":" + SystemInfo.graphicsDeviceVendorID + "\n" +
"SystemInfo.graphicsDeviceVersion" + ":" + SystemInfo.graphicsDeviceVersion + "\n" +
"SystemInfo.graphicsMemorySize" + ":" + SystemInfo.graphicsMemorySize + "\n" +
"SystemInfo.graphicsMultiThreaded" + ":" + SystemInfo.graphicsMultiThreaded + "\n" +
"SystemInfo.graphicsPixelFillrate" + ":" + SystemInfo.graphicsPixelFillrate + "\n" +
"SystemInfo.graphicsShaderLevel" + ":" + SystemInfo.graphicsShaderLevel + "\n" +
"SystemInfo.graphicsUVStartsAtTop" + ":" + SystemInfo.graphicsUVStartsAtTop + "\n" +
"SystemInfo.hasDynamicUniformArrayIndexingInFragmentShaders" + ":" + SystemInfo.hasDynamicUniformArrayIndexingInFragmentShaders + "\n" +
"SystemInfo.hasHiddenSurfaceRemovalOnGPU" + ":" + SystemInfo.hasHiddenSurfaceRemovalOnGPU + "\n" +
"SystemInfo.hasMipMaxLevel" + ":" + SystemInfo.hasMipMaxLevel + "\n" +
"SystemInfo.hdrDisplaySupportFlags" + ":" + SystemInfo.hdrDisplaySupportFlags + "\n" +
"SystemInfo.maxComputeBufferInputsCompute" + ":" + SystemInfo.maxComputeBufferInputsCompute + "\n" +
"SystemInfo.maxComputeBufferInputsDomain" + ":" + SystemInfo.maxComputeBufferInputsDomain + "\n" +
"SystemInfo.maxComputeBufferInputsFragment" + ":" + SystemInfo.maxComputeBufferInputsFragment + "\n" +
"SystemInfo.maxComputeBufferInputsGeometry" + ":" + SystemInfo.maxComputeBufferInputsGeometry + "\n" +
"SystemInfo.maxComputeBufferInputsHull" + ":" + SystemInfo.maxComputeBufferInputsHull + "\n" +
"SystemInfo.maxComputeBufferInputsVertex" + ":" + SystemInfo.maxComputeBufferInputsVertex + "\n" +
"SystemInfo.maxComputeWorkGroupSize" + ":" + SystemInfo.maxComputeWorkGroupSize + "\n" +
"SystemInfo.maxComputeWorkGroupSizeX" + ":" + SystemInfo.maxComputeWorkGroupSizeX + "\n" +
"SystemInfo.maxComputeWorkGroupSizeY" + ":" + SystemInfo.maxComputeWorkGroupSizeY + "\n" +
"SystemInfo.maxComputeWorkGroupSizeZ" + ":" + SystemInfo.maxComputeWorkGroupSizeZ + "\n" +
"SystemInfo.maxCubemapSize" + ":" + SystemInfo.maxCubemapSize + "\n" +
"SystemInfo.maxTextureSize" + ":" + SystemInfo.maxTextureSize + "\n" +
"SystemInfo.minConstantBufferOffsetAlignment" + ":" + SystemInfo.minConstantBufferOffsetAlignment + "\n" +
"SystemInfo.npotSupport" + ":" + SystemInfo.npotSupport + "\n" +
"SystemInfo.operatingSystem" + ":" + SystemInfo.operatingSystem + "\n" +
"SystemInfo.operatingSystemFamily" + ":" + SystemInfo.operatingSystemFamily + "\n" +
"SystemInfo.processorCount" + ":" + SystemInfo.processorCount + "\n" +
"SystemInfo.processorFrequency" + ":" + SystemInfo.processorFrequency + "\n" +
"SystemInfo.processorType" + ":" + SystemInfo.processorType + "\n" +
"SystemInfo.renderingThreadingMode" + ":" + SystemInfo.renderingThreadingMode + "\n" +
"SystemInfo.supportedRandomWriteTargetCount" + ":" + SystemInfo.supportedRandomWriteTargetCount + "\n" +
"SystemInfo.supportedRenderTargetCount" + ":" + SystemInfo.supportedRenderTargetCount + "\n" +
"SystemInfo.supports2DArrayTextures" + ":" + SystemInfo.supports2DArrayTextures + "\n" +
"SystemInfo.supports32bitsIndexBuffer" + ":" + SystemInfo.supports32bitsIndexBuffer + "\n" +
"SystemInfo.supports3DRenderTextures" + ":" + SystemInfo.supports3DRenderTextures + "\n" +
"SystemInfo.supports3DTextures" + ":" + SystemInfo.supports3DTextures + "\n" +
"SystemInfo.supportsAccelerometer" + ":" + SystemInfo.supportsAccelerometer + "\n" +
"SystemInfo.supportsAsyncCompute" + ":" + SystemInfo.supportsAsyncCompute + "\n" +
"SystemInfo.supportsAsyncGPUReadback" + ":" + SystemInfo.supportsAsyncGPUReadback + "\n" +
"SystemInfo.supportsAudio" + ":" + SystemInfo.supportsAudio + "\n" +
"SystemInfo.supportsCompressed3DTextures" + ":" + SystemInfo.supportsCompressed3DTextures + "\n" +
"SystemInfo.supportsComputeShaders" + ":" + SystemInfo.supportsComputeShaders + "\n" +
"SystemInfo.supportsConservativeRaster" + ":" + SystemInfo.supportsConservativeRaster + "\n" +
"SystemInfo.supportsCubemapArrayTextures" + ":" + SystemInfo.supportsCubemapArrayTextures + "\n" +
"SystemInfo.supportsGeometryShaders" + ":" + SystemInfo.supportsGeometryShaders + "\n" +
"SystemInfo.supportsGpuRecorder" + ":" + SystemInfo.supportsGpuRecorder + "\n" +
"SystemInfo.supportsGraphicsFence" + ":" + SystemInfo.supportsGraphicsFence + "\n" +
"SystemInfo.supportsGyroscope" + ":" + SystemInfo.supportsGyroscope + "\n" +
"SystemInfo.supportsHardwareQuadTopology" + ":" + SystemInfo.supportsHardwareQuadTopology + "\n" +
"SystemInfo.supportsImageEffects" + ":" + SystemInfo.supportsImageEffects + "\n" +
"SystemInfo.supportsInstancing" + ":" + SystemInfo.supportsInstancing + "\n" +
"SystemInfo.supportsLocationService" + ":" + SystemInfo.supportsLocationService + "\n" +
"SystemInfo.supportsMipStreaming" + ":" + SystemInfo.supportsMipStreaming + "\n" +
"SystemInfo.supportsMotionVectors" + ":" + SystemInfo.supportsMotionVectors + "\n" +
"SystemInfo.supportsMultisampleAutoResolve" + ":" + SystemInfo.supportsMultisampleAutoResolve + "\n" +
"SystemInfo.supportsMultisampled2DArrayTextures" + ":" + SystemInfo.supportsMultisampled2DArrayTextures + "\n" +
"SystemInfo.supportsMultisampledTextures" + ":" + SystemInfo.supportsMultisampledTextures + "\n" +
"SystemInfo.supportsMultiview" + ":" + SystemInfo.supportsMultiview + "\n" +
"SystemInfo.supportsRawShadowDepthSampling" + ":" + SystemInfo.supportsRawShadowDepthSampling + "\n" +
"SystemInfo.supportsRayTracing" + ":" + SystemInfo.supportsRayTracing + "\n" +
"SystemInfo.supportsRenderTargetArrayIndexFromVertexShader" + ":" + SystemInfo.supportsRenderTargetArrayIndexFromVertexShader + "\n" +
"SystemInfo.supportsRenderTextures" + ":" + SystemInfo.supportsRenderTextures + "\n" +
"SystemInfo.supportsRenderToCubemap" + ":" + SystemInfo.supportsRenderToCubemap + "\n" +
"SystemInfo.supportsSeparatedRenderTargetsBlend" + ":" + SystemInfo.supportsSeparatedRenderTargetsBlend + "\n" +
"SystemInfo.supportsSetConstantBuffer" + ":" + SystemInfo.supportsSetConstantBuffer + "\n" +
"SystemInfo.supportsShadows" + ":" + SystemInfo.supportsShadows + "\n" +
"SystemInfo.supportsSparseTextures" + ":" + SystemInfo.supportsSparseTextures + "\n" +
"SystemInfo.supportsStencil" + ":" + SystemInfo.supportsStencil + "\n" +
"SystemInfo.supportsTessellationShaders" + ":" + SystemInfo.supportsTessellationShaders + "\n" +
"SystemInfo.supportsTextureWrapMirrorOnce" + ":" + SystemInfo.supportsTextureWrapMirrorOnce + "\n" +
"SystemInfo.supportsVertexPrograms" + ":" + SystemInfo.supportsVertexPrograms + "\n" +
"SystemInfo.supportsVibration" + ":" + SystemInfo.supportsVibration + "\n" +
"SystemInfo.systemMemorySize" + ":" + SystemInfo.systemMemorySize + "\n" +
"SystemInfo.usesLoadStoreActions" + ":" + SystemInfo.usesLoadStoreActions + "\n" +
"SystemInfo.usesReversedZBuffer" + ":" + SystemInfo.usesReversedZBuffer + "";
最后发现在模拟器上面:
SystemInfo.graphicsDeviceID = 0;
SystemInfo.graphicsDeviceVendorID = 0;
在手机上面测试是有值的
还有一个这个方法:获取设备固件版本号
public string IsRunningOnEmulator6()
{
if (Application.platform == RuntimePlatform.Android)
{
AndroidJavaClass buildClass = new AndroidJavaClass("android.os.Build");
string radioVersion = buildClass.CallStatic<string>("getRadioVersion");
return radioVersion;
}
return "";
}
这个也是在手机上面有,模拟器上面是没有的
最后附上模拟器打印的参数: