/// <summary> /// 获取设备类型 /// </summary> /// <param name="DeviceValues"></param> /// <returns></returns> private static MTPDeviceType GetDeviceType(IPortableDeviceValues DeviceValues) { _tagpropertykey deviceTypeKey = new _tagpropertykey() { fmtid = new Guid("26d4979a-e643-4626-9e2b-736dc0c92fdc"), pid = 15 }; uint propertyValue; DeviceValues.GetUnsignedIntegerValue(ref deviceTypeKey, out propertyValue); MTPDeviceType deviceType = (MTPDeviceType)propertyValue; return(deviceType); }
public static List <MTPDevice> GetDevices() { var devices = new List <MTPDevice>(); string[] deviceIds = EnumerateDevices(); PortableDevice portableDevice; IPortableDeviceContent deviceContent; MTPDevice tempDevice; if (!deviceIds.IsValid()) { return(devices); } foreach (var deviceId in deviceIds) { IPortableDeviceValues deviceValues = Connect(deviceId, out portableDevice, out deviceContent); MTPDeviceType deviceType = GetDeviceType(deviceValues); //if (deviceType == MTPDeviceType.MediaPlayer || deviceType == MTPDeviceType.Phone) { try { tempDevice = new MTPDevice(); tempDevice.DeviceId = deviceId; tempDevice.DeviceType = deviceType; tempDevice.SerialNumber = GetSerialNumber(deviceValues); tempDevice.DeviceName = GetDeviceName(deviceValues); tempDevice.FirmwareVersion = GetFirmwareVersion(deviceValues); tempDevice.Manufacturer = GetManufacturer(deviceValues); tempDevice.Model = GetModel(deviceValues); devices.Add(tempDevice); } catch { } } Disconnect(portableDevice); } return(devices); }