Windows Phone 硬件检测

Windows Phone 硬件检测 


介绍

随着Lumia的日益壮大,手机的硬件配置也越来越多样化,要想让你的应用在不同配置的手机上能更好的展现,作为开发者,你就不能不去了解一下手机的硬件配置。 Lumia系列WP8手机配置对比 并且,你还需要知道如何获取这些配置信息。

Windows Phone 8 手机分辨率

Hardware Finder 1.png

private static bool IsWvga
{
    get { return App.Current.Host.Content.ScaleFactor == 100; }
}
 
private static bool IsWxga
{
    get { return App.Current.Host.Content.ScaleFactor == 160; }
}
 
private static bool Is720p
{
    get { return App.Current.Host.Content.ScaleFactor == 150; }
}

硬件配置

摄像头(Camera)

#if WINDOWS_PHONE_8   // Windows Phone 8
    try
    {
        BackCameraExist = PhotoCaptureDevice.AvailableSensorLocations.Contains<CameraSensorLocation>(CameraSensorLocation.Back);
        FrontCameraExist = PhotoCaptureDevice.AvailableSensorLocations.Contains<CameraSensorLocation>(CameraSensorLocation.Front);
    }
    catch (System.Exception e)
    {
        MessageBox.Show(e.Message);
    }
 
#else  // Windows Phone 7  
    FrontCameraExist = Microsoft.Devices.Camera.IsCameraTypeSupported(Microsoft.Devices.CameraType.FrontFacing);
    BackCameraExist = Microsoft.Devices.Camera.IsCameraTypeSupported(Microsoft.Devices.CameraType.Primary);
#endif

罗盘(Compass)

#if WINDOWS_PHONE_8  // Windows Phone 8
    if (Compass.GetDefault() != null)
    {
        CompassExist = true;
    }
 
#else  // Windows Phone 7
    CompassExist = Microsoft.Devices.Sensors.Compass.IsSupported;
#endif

NFC

#if WINDOWS_PHONE_8  // Windows Phone 8
    // ID_CAP_NETWORKING ID_CAP_PROXIMITY
    if (ProximityDevice.GetDefault() != null)
    {
        ProximityExist = true;
    }
#else  // Windows Phone 7 
    // Windows Phone 7 不支持NFC功能
#endif

陀螺仪(Gyroscope)

#if WINDOWS_PHONE_8  // Windows Phone 8
    // 目前Gyrometer.GetDefault()在陀螺仪不支持时会抛出异常,以MSDN文档描述的返回null不符。
    try
    {
        if (Gyrometer.GetDefault() != null)
        {
            GyroscopeExist = true;
        }
    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
    }
 
#else  // Windows Phone 7
    GyroscopeExist = Microsoft.Devices.Sensors.Gyroscope.IsSupported;
#endif

加速传感器(Accelerometer)

#if WINDOWS_PHONE_8  // Windows Phone 8
    if (Accelerometer.GetDefault() != null)
    {
        AccelerometerExist = true;
    }
 
#else  // Windows Phone 7
    AccelerometerExist = Microsoft.Devices.Sensors.Accelerometer.IsSupported;
#endif

磁倾仪传感器(Inclinometer)

#if WINDOWS_PHONE_8  // Windows Phone 8
    if (Windows.Devices.Sensors.Inclinometer.GetDefault() != null)
    {
        InclinometerExist = true;
    }
 
#else  // Windows Phone 7
    // Windows Phone 7 不支持
#endif

方向传感器(Orientation)

#if WINDOWS_PHONE_8  // Windows Phone 8
    if (Windows.Devices.Sensors.OrientationSensor.GetDefault() != null)
    {
        OrientationSensorExist = true;
    }
 
#else  // Windows Phone 7
    OrientationSensorExist = Microsoft.Devices.Sensors.Motion.IsSupported;
#endif

震动设备(VibrationDevice)

#if WINDOWS_PHONE_8  // Windows Phone 8
    if (Windows.Phone.Devices.Notification.VibrationDevice.GetDefault() != null)
    {
        VibrationDeviceExist = true;
    }
 
#else  // Windows Phone 7
    if (Microsoft.Devices.VibrateController.Default != null)
    {
        VibrationDeviceExist = true;
    }
#endif

电量传感器(Battery)

#if WINDOWS_PHONE_8  // Windows Phone 8
    if (Windows.Phone.Devices.Power.Battery.GetDefault() != null)
    {
        BatterySensorExist = true;
    }
 
#else  // Windows Phone 7
    // Windows Phone 7 不支持
#endif

内存判断(Memory)

#if WINDOWS_PHONE_8 // Windows Phone 8
    MemoryCurrentUsed = Windows.Phone.System.Memory.MemoryManager.ProcessCommittedBytes.ToString();
    MemoryMaxAvailable = Windows.Phone.System.Memory.MemoryManager.ProcessCommittedLimit.ToString();
 
#else  // Windows Phone 7
    // 通过DeviceExtendedProperties类获取
#endif

Windows Phone 应用的功能和硬件要求

在获取设备硬件信息之前,你还 需要在清单文件中标记你的应用需要的功能(CAPABILITIES) 。另外你还 可以在清单文件中指定应用的硬件要求(REQUIREMENTS),以确保只有满足硬件要求的设备才能在应用商店中查看并下载安装你的应用

要了解应用功能和硬件要求,可以在下面链接查看: http://msdn.microsoft.com/zh-cn/library/windowsphone/develop/jj206936.aspx

应用清单文件

文件路径:工程目录->Properties->WMAppManifest.xml

Hardware Finder 2.png

应用清单文件设计器(Windows Phone 8)

Hardware Finder 3.png

Hardware Finder 4.png

我们可以通过清单文件设计器来标记应用的功能和硬件要求,但是在设计器中不能够标记全部的功能或硬件要求(比如ID_REQ_MEMORY_300),这时你就需要用“查看代码”的方式打开WMAppManifest.xml文件进行编辑。

Hardware Finder 5.png

示例代码

File:HardwareFinder.zip

 

 

http://www.developer.nokia.com/Community/Wiki/Windows_Phone_%E7%A1%AC%E4%BB%B6%E6%A3%80%E6%B5%8B

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值