最近有个需求,需要判断当前设备是否是模拟器,网上查了一下,发现基本上都是使用特征字符串进行检索,类似这种:
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" + ":<color=#ff0000>" + SystemInfo.batteryLevel + "</color>\n" +
"SystemInfo.deviceModel" + ":<color=#FF0000>" + SystemInfo.deviceModel + "</color>\n" +
"SystemInfo.batteryStatus" + ":<color=#FF0000>" + SystemInfo.batteryStatus + "</color>\n" +
"SystemInfo.constantBufferOffsetAlignment" + ":<color=#FF0000>" + SystemInfo.constantBufferOffsetAlignment + "</color>\n" +
"SystemInfo.copyTextureSupport" + ":<color=#FF0000>" + SystemInfo.copyTextureSupport + "</color>\n" +
"SystemInfo.deviceName" + ":<color=#FF0000>" + SystemInfo.deviceName + "</color>\n" +
"SystemInfo.deviceType" + ":<color=#FF0000>" + SystemInfo.deviceType + "</color>\n" +
"SystemInfo.deviceUniqueIdentifier" + ":<color=#FF0000>" + SystemInfo.deviceUniqueIdentifier + "</color>\n" +
"SystemInfo.graphicsDeviceID" + ":<color=#FF0000>" + SystemInfo.graphicsDeviceID + "</color>\n" +
"SystemInfo.graphicsDeviceName" + ":<color=#FF0000>" + SystemInfo.graphicsDeviceName + "</color>\n" +
"SystemInfo.graphicsDeviceType" + ":<color=#FF0000>" + SystemInfo.graphicsDeviceType + "</color>\n" +
"SystemInfo.graphicsDeviceVendor" + ":<color=#FF0000>" + SystemInfo.graphicsDeviceVendor + "</color>\n" +
"SystemInfo.graphicsDeviceVendorID" + ":<color=#FF0000>" + SystemInfo.graphicsDeviceVendorID + "</color>\n" +
"SystemInfo.graphicsDeviceVersion" + ":<color=#FF0000>" + SystemInfo.graphicsDeviceVersion + "</color>\n" +
"SystemInfo.graphicsMemorySize" + ":<color=#FF0000>" + SystemInfo.graphicsMemorySize + "</color>\n" +
"SystemInfo.graphicsMultiThreaded" + ":<color=#FF0000>" + SystemInfo.graphicsMultiThreaded + "</color>\n" +
"SystemInfo.graphicsPixelFillrate" + ":<color=#FF0000>" + SystemInfo.graphicsPixelFillrate + "</color>\n" +
"SystemInfo.graphicsShaderLevel" + ":<color=#FF0000>" + SystemInfo.graphicsShaderLevel + "</color>\n" +
"SystemInfo.graphicsUVStartsAtTop" + ":<color=#FF0000>" + SystemInfo.graphicsUVStartsAtTop + "</color>\n" +
"SystemInfo.hasDynamicUniformArrayIndexingInFragmentShaders" + ":<color=#FF0000>" + SystemInfo.hasDynamicUniformArrayIndexingInFragmentShaders + "</color>\n" +
"SystemInfo.hasHiddenSurfaceRemovalOnGPU" + ":<color=#FF0000>" + SystemInfo.hasHiddenSurfaceRemovalOnGPU + "</color>\n" +
"SystemInfo.hasMipMaxLevel" + ":<color=#FF0000>" + SystemInfo.hasMipMaxLevel + "</color>\n" +
"SystemInfo.hdrDisplaySupportFlags" + ":<color=#FF0000>" + SystemInfo.hdrDisplaySupportFlags + "</color>\n" +
"SystemInfo.maxComputeBufferInputsCompute" + ":<color=#FF0000>" + SystemInfo.maxComputeBufferInputsCompute + "</color>\n" +
"SystemInfo.maxComputeBufferInputsDomain" + ":<color=#FF0000>" + SystemInfo.maxComputeBufferInputsDomain + "</color>\n" +
"SystemInfo.maxComputeBufferInputsFragment" + ":<color=#FF0000>" + SystemInfo.maxComputeBufferInputsFragment + "</color>\n" +
"SystemInfo.maxComputeBufferInputsGeometry" + ":<color=#FF0000>" + SystemInfo.maxComputeBufferInputsGeometry + "</color>\n" +
"SystemInfo.maxComputeBufferInputsHull" + ":<color=#FF0000>" + SystemInfo.maxComputeBufferInputsHull + "</color>\n" +
"SystemInfo.maxComputeBufferInputsVertex" + ":<color=#FF0000>" + SystemInfo.maxComputeBufferInputsVertex + "</color>\n" +
"SystemInfo.maxComputeWorkGroupSize" + ":<color=#FF0000>" + SystemInfo.maxComputeWorkGroupSize + "</color>\n" +
"SystemInfo.maxComputeWorkGroupSizeX" + ":<color=#FF0000>" + SystemInfo.maxComputeWorkGroupSizeX + "</color>\n" +
"SystemInfo.maxComputeWorkGroupSizeY" + ":<color=#FF0000>" + SystemInfo.maxComputeWorkGroupSizeY + "</color>\n" +
"SystemInfo.maxComputeWorkGroupSizeZ" + ":<color=#FF0000>" + SystemInfo.maxComputeWorkGroupSizeZ + "</color>\n" +
"SystemInfo.maxCubemapSize" + ":<color=#FF0000>" + SystemInfo.maxCubemapSize + "</color>\n" +
"SystemInfo.maxTextureSize" + ":<color=#FF0000>" + SystemInfo.maxTextureSize + "</color>\n" +
"SystemInfo.minConstantBufferOffsetAlignment" + ":<color=#FF0000>" + SystemInfo.minConstantBufferOffsetAlignment + "</color>\n" +
"SystemInfo.npotSupport" + ":<color=#FF0000>" + SystemInfo.npotSupport + "</color>\n" +
"SystemInfo.operatingSystem" + ":<color=#FF0000>" + SystemInfo.operatingSystem + "</color>\n" +
"SystemInfo.operatingSystemFamily" + ":<color=#FF0000>" + SystemInfo.operatingSystemFamily + "</color>\n" +
"SystemInfo.processorCount" + ":<color=#FF0000>" + SystemInfo.processorCount + "</color>\n" +
"SystemInfo.processorFrequency" + ":<color=#FF0000>" + SystemInfo.processorFrequency + "</color>\n" +
"SystemInfo.processorType" + ":<color=#FF0000>" + SystemInfo.processorType + "</color>\n" +
"SystemInfo.renderingThreadingMode" + ":<color=#FF0000>" + SystemInfo.renderingThreadingMode + "</color>\n" +
"SystemInfo.supportedRandomWriteTargetCount" + ":<color=#FF0000>" + SystemInfo.supportedRandomWriteTargetCount + "</color>\n" +
"SystemInfo.supportedRenderTargetCount" + ":<color=#FF0000>" + SystemInfo.supportedRenderTargetCount + "</color>\n" +
"SystemInfo.supports2DArrayTextures" + ":<color=#FF0000>" + SystemInfo.supports2DArrayTextures + "</color>\n" +
"SystemInfo.supports32bitsIndexBuffer" + ":<color=#FF0000>" + SystemInfo.supports32bitsIndexBuffer + "</color>\n" +
"SystemInfo.supports3DRenderTextures" + ":<color=#FF0000>" + SystemInfo.supports3DRenderTextures + "</color>\n" +
"SystemInfo.supports3DTextures" + ":<color=#FF0000>" + SystemInfo.supports3DTextures + "</color>\n" +
"SystemInfo.supportsAccelerometer" + ":<color=#FF0000>" + SystemInfo.supportsAccelerometer + "</color>\n" +
"SystemInfo.supportsAsyncCompute" + ":<color=#FF0000>" + SystemInfo.supportsAsyncCompute + "</color>\n" +
"SystemInfo.supportsAsyncGPUReadback" + ":<color=#FF0000>" + SystemInfo.supportsAsyncGPUReadback + "</color>\n" +
"SystemInfo.supportsAudio" + ":<color=#FF0000>" + SystemInfo.supportsAudio + "</color>\n" +
"SystemInfo.supportsCompressed3DTextures" + ":<color=#FF0000>" + SystemInfo.supportsCompressed3DTextures + "</color>\n" +
"SystemInfo.supportsComputeShaders" + ":<color=#FF0000>" + SystemInfo.supportsComputeShaders + "</color>\n" +
"SystemInfo.supportsConservativeRaster" + ":<color=#FF0000>" + SystemInfo.supportsConservativeRaster + "</color>\n" +
"SystemInfo.supportsCubemapArrayTextures" + ":<color=#FF0000>" + SystemInfo.supportsCubemapArrayTextures + "</color>\n" +
"SystemInfo.supportsGeometryShaders" + ":<color=#FF0000>" + SystemInfo.supportsGeometryShaders + "</color>\n" +
"SystemInfo.supportsGpuRecorder" + ":<color=#FF0000>" + SystemInfo.supportsGpuRecorder + "</color>\n" +
"SystemInfo.supportsGraphicsFence" + ":<color=#FF0000>" + SystemInfo.supportsGraphicsFence + "</color>\n" +
"SystemInfo.supportsGyroscope" + ":<color=#FF0000>" + SystemInfo.supportsGyroscope + "</color>\n" +
"SystemInfo.supportsHardwareQuadTopology" + ":<color=#FF0000>" + SystemInfo.supportsHardwareQuadTopology + "</color>\n" +
"SystemInfo.supportsImageEffects" + ":<color=#FF0000>" + SystemInfo.supportsImageEffects + "</color>\n" +
"SystemInfo.supportsInstancing" + ":<color=#FF0000>" + SystemInfo.supportsInstancing + "</color>\n" +
"SystemInfo.supportsLocationService" + ":<color=#FF0000>" + SystemInfo.supportsLocationService + "</color>\n" +
"SystemInfo.supportsMipStreaming" + ":<color=#FF0000>" + SystemInfo.supportsMipStreaming + "</color>\n" +
"SystemInfo.supportsMotionVectors" + ":<color=#FF0000>" + SystemInfo.supportsMotionVectors + "</color>\n" +
"SystemInfo.supportsMultisampleAutoResolve" + ":<color=#FF0000>" + SystemInfo.supportsMultisampleAutoResolve + "</color>\n" +
"SystemInfo.supportsMultisampled2DArrayTextures" + ":<color=#FF0000>" + SystemInfo.supportsMultisampled2DArrayTextures + "</color>\n" +
"SystemInfo.supportsMultisampledTextures" + ":<color=#FF0000>" + SystemInfo.supportsMultisampledTextures + "</color>\n" +
"SystemInfo.supportsMultiview" + ":<color=#FF0000>" + SystemInfo.supportsMultiview + "</color>\n" +
"SystemInfo.supportsRawShadowDepthSampling" + ":<color=#FF0000>" + SystemInfo.supportsRawShadowDepthSampling + "</color>\n" +
"SystemInfo.supportsRayTracing" + ":<color=#FF0000>" + SystemInfo.supportsRayTracing + "</color>\n" +
"SystemInfo.supportsRenderTargetArrayIndexFromVertexShader" + ":<color=#FF0000>" + SystemInfo.supportsRenderTargetArrayIndexFromVertexShader + "</color>\n" +
"SystemInfo.supportsRenderTextures" + ":<color=#FF0000>" + SystemInfo.supportsRenderTextures + "</color>\n" +
"SystemInfo.supportsRenderToCubemap" + ":<color=#FF0000>" + SystemInfo.supportsRenderToCubemap + "</color>\n" +
"SystemInfo.supportsSeparatedRenderTargetsBlend" + ":<color=#FF0000>" + SystemInfo.supportsSeparatedRenderTargetsBlend + "</color>\n" +
"SystemInfo.supportsSetConstantBuffer" + ":<color=#FF0000>" + SystemInfo.supportsSetConstantBuffer + "</color>\n" +
"SystemInfo.supportsShadows" + ":<color=#FF0000>" + SystemInfo.supportsShadows + "</color>\n" +
"SystemInfo.supportsSparseTextures" + ":<color=#FF0000>" + SystemInfo.supportsSparseTextures + "</color>\n" +
"SystemInfo.supportsStencil" + ":<color=#FF0000>" + SystemInfo.supportsStencil + "</color>\n" +
"SystemInfo.supportsTessellationShaders" + ":<color=#FF0000>" + SystemInfo.supportsTessellationShaders + "</color>\n" +
"SystemInfo.supportsTextureWrapMirrorOnce" + ":<color=#FF0000>" + SystemInfo.supportsTextureWrapMirrorOnce + "</color>\n" +
"SystemInfo.supportsVertexPrograms" + ":<color=#FF0000>" + SystemInfo.supportsVertexPrograms + "</color>\n" +
"SystemInfo.supportsVibration" + ":<color=#FF0000>" + SystemInfo.supportsVibration + "</color>\n" +
"SystemInfo.systemMemorySize" + ":<color=#FF0000>" + SystemInfo.systemMemorySize + "</color>\n" +
"SystemInfo.usesLoadStoreActions" + ":<color=#FF0000>" + SystemInfo.usesLoadStoreActions + "</color>\n" +
"SystemInfo.usesReversedZBuffer" + ":<color=#FF0000>" + SystemInfo.usesReversedZBuffer + "</color>";
最后发现在模拟器上面:
SystemInfo.graphicsDeviceID = 0;
SystemInfo.graphicsDeviceVendorID = 0;
在手机上面测试是有值的
还有一个这个方法:获取设备固件版本号文章来源:https://www.toymoban.com/news/detail-626742.html
public string IsRunningOnEmulator6()
{
if (Application.platform == RuntimePlatform.Android)
{
AndroidJavaClass buildClass = new AndroidJavaClass("android.os.Build");
string radioVersion = buildClass.CallStatic<string>("getRadioVersion");
return radioVersion;
}
return "";
}
这个也是在手机上面有,模拟器上面是没有的
最后附上模拟器打印的参数:
文章来源地址https://www.toymoban.com/news/detail-626742.html
到了这里,关于unity 判断当前设备是否是模拟器(安卓)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!