디바이스 정보

Browse sample. 샘플 찾아보기

이 문서에서는 .NET 다중 플랫폼 앱 UI(.NET MAUI) IDeviceInfo 인터페이스를 사용하여 앱이 실행 중인 디바이스에 대한 정보를 읽는 방법을 설명합니다.

인터페이스의 IDeviceInfo 기본 구현은 속성을 통해 DeviceInfo.Current 사용할 수 있습니다. IDeviceInfo 인터페이스와 DeviceInfo 클래스는 모두 네임스페이스에 Microsoft.Maui.Devices 포함됩니다.

디바이스 정보 읽기

인터페이스는 IDeviceInfo 제조업체 및 관용구와 같이 디바이스를 설명하는 많은 속성을 제공합니다. 다음 예제에서는 디바이스 정보 속성을 읽는 방법을 보여 줍니다.

private void ReadDeviceInfo()
{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();

    sb.AppendLine($"Model: {DeviceInfo.Current.Model}");
    sb.AppendLine($"Manufacturer: {DeviceInfo.Current.Manufacturer}");
    sb.AppendLine($"Name: {DeviceInfo.Current.Name}");
    sb.AppendLine($"OS Version: {DeviceInfo.Current.VersionString}");
    sb.AppendLine($"Idiom: {DeviceInfo.Current.Idiom}");
    sb.AppendLine($"Platform: {DeviceInfo.Current.Platform}");

    bool isVirtual = DeviceInfo.Current.DeviceType switch
    {
        DeviceType.Physical => false,
        DeviceType.Virtual => true,
        _ => false
    };

    sb.AppendLine($"Virtual device? {isVirtual}");

    DisplayDeviceLabel.Text = sb.ToString();
}

디바이스 플랫폼 가져오기

이 속성은 IDeviceInfo.Platform 앱이 실행 중인 운영 체제를 나타냅니다. 이 형식은 DevicePlatform 각 운영 체제에 대한 속성을 제공합니다.

다음 예제에서는 속성이 운영 체제와 일치하는 AndroidIDeviceInfo.Platform 검사 보여 줍니다.

private bool IsAndroid() =>
    DeviceInfo.Current.Platform == DevicePlatform.Android;

디바이스 유형 가져오기

이 속성은 IDeviceInfo.Idiom 데스크톱 컴퓨터 또는 태블릿과 같이 앱이 실행 중인 디바이스의 유형을 나타냅니다. 이 형식은 DeviceIdiom 디바이스의 각 유형에 대한 속성을 제공합니다.

다음 예제에서는 값을 속성과 IDeviceInfo.Idiom 비교하는 방법을 DeviceIdiom 보여 줍니다.

private void PrintIdiom()
{
    if (DeviceInfo.Current.Idiom == DeviceIdiom.Desktop)
        Console.WriteLine("The current device is a desktop");
    else if (DeviceInfo.Current.Idiom == DeviceIdiom.Phone)
        Console.WriteLine("The current device is a phone");
    else if (DeviceInfo.Current.Idiom == DeviceIdiom.Tablet)
        Console.WriteLine("The current device is a Tablet");
}

디바이스 유형

IDeviceInfo.DeviceType 속성은 애플리케이션이 물리적 또는 가상 디바이스에서 실행 중인지 확인하기 위한 열거형입니다. 가상 디바이스는 시뮬레이터 또는 에뮬레이터입니다.

bool isVirtual = DeviceInfo.Current.DeviceType switch
{
    DeviceType.Physical => false,
    DeviceType.Virtual => true,
    _ => false
};

플랫폼 간 차이점

이 섹션에서는 디바이스 정보와 플랫폼별 차이점을 설명합니다.

플랫폼의 차이점이 없습니다.