[OS/WINDOWS] powercfg 명령 : 배터리 보고서 생성 후 배터리 성능 확인하기
■ powercfg 명령을 사용해 배터리 보고서 생성 후 배터리 성능을 확인하는 방법을 보여준다. 1. [명령 프롬프트]를 실행한다. 2. [명령 프롬프트]에서 아래 명령을
■ powercfg 명령을 사용해 배터리 보고서 생성 후 배터리 성능을 확인하는 방법을 보여준다. 1. [명령 프롬프트]를 실행한다. 2. [명령 프롬프트]에서 아래 명령을
■ IMediaPicker 인터페이스의 PickPhotoAsync 메소드를 사용해 갤러리 사진을 구하는 방법을 보여준다. ▶ Platforms/Android/AndroidManifest.xml
1 2 3 4 5 6 7 8 9 10 11 12 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> </manifest> |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <StackLayout HorizontalOptions="Center" VerticalOptions="Center" Spacing="10"> <Border HorizontalOptions="Center" StrokeThickness="5" Stroke="Gray"> <Border.StrokeShape> <Rectangle /> </Border.StrokeShape> <Image x:Name="image" WidthRequest="300" HeightRequest="300" Aspect="Fill" /> </Border> <Button x:Name="pickButton" HorizontalOptions="Center" Text="사진 파일 선택하기" /> </StackLayout> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.pickButton.Clicked += pickButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 사진 파일 선택하기 버튼 클릭시 처리하기 - pickButton_Clicked(sender, e) /// <summary> /// 사진 파일 선택하기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private async void pickButton_Clicked(object sender, EventArgs e) { if(MediaPicker.Default.IsCaptureSupported) { FileResult fileResult = await MediaPicker.Default.PickPhotoAsync(); if(fileResult != null) { Stream stream = await fileResult.OpenReadAsync(); this.image.Source = ImageSource.FromStream(() => stream); } } } #endregion } |
TestProject.zip
■ IMediaPicker 인터페이스의 CapturePhotoAsync 메소드를 사용해 사진을 촬영하는 방법을 보여준다. (ANDROID) ▶ Platforms/Andriod/Resources/AndroidManifest.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.CAMERA" /> <queries> <intent> <action android:name="android.media.action.IMAGE_CAPTURE" /> </intent> </queries> </manifest> |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Button x:Name="takeButton" HorizontalOptions="Center" VerticalOptions="Center" Text="사진 촬영하기" /> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.takeButton.Clicked += takeButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 사진 촬영하기 버튼 클릭시 처리하기 - takeButton_Clicked(sender, e) /// <summary> /// 사진 촬영하기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private async void takeButton_Clicked(object sender, EventArgs e) { if(MediaPicker.Default.IsCaptureSupported) { FileResult fileResult = await MediaPicker.Default.CapturePhotoAsync(); if(fileResult != null) { string filePath = Path.Combine(FileSystem.CacheDirectory, fileResult.FileName); using Stream stream = await fileResult.OpenReadAsync(); using FileStream fileStream = File.OpenWrite(filePath); await stream.CopyToAsync(fileStream); } } } #endregion } |
TestProject.zip
■ IVibration 인터페이스의 Vibrate 메소드를 사용해 진동시키는 방법을 보여준다. ▶ Platforms/Andriod/Resources/AndroidManifest.xml
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.VIBRATE" /> </manifest> |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Button x:Name="vibrationButton" HorizontalOptions="Center" VerticalOptions="Center" Text="진동시키기" /> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.vibrationButton.Clicked += vibrationButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 진동시키기 버튼 클릭시 처리하기 - vibrationButton_Clicked(sender, e) /// <summary> /// 진동시키기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void vibrationButton_Clicked(object sender, EventArgs e) { TimeSpan vibrationLength = TimeSpan.FromSeconds(Random.Shared.Next(1, 3)); Vibration.Default.Vibrate(vibrationLength); } #endregion } |
TestProject.zip
■ IHapticFeedback 인터페이스의 Perform 메소드를 사용해 햅틱 피드백을 진동시키는 방법을 보여준다. ▶ Platforms/Andriod/Resources/AndroidManifest.xml
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.VIBRATE" /> </manifest> |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <StackLayout HorizontalOptions="Center" VerticalOptions="Center" Spacing="10"> <Button x:Name="clickButton" HorizontalOptions="Center" Text="클릭시 진동시키기" /> <Button x:Name="longPressButton" HorizontalOptions="Center" Text="길게 누르는 경우 진동시키기" /> </StackLayout> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.clickButton.Clicked += clickButton_Clicked; this.longPressButton.Clicked += longPressButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 클릭시 진동시키기 버튼 클릭시 처리하기 - clickButton_Clicked(sender, e) /// <summary> /// 클릭시 진동시키기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void clickButton_Clicked(object sender, EventArgs e) { HapticFeedback.Default.Perform(HapticFeedbackType.Click); } #endregion #region 길게 누른 경우 진동시키기 버튼 클릭시 처리하기 - longPressButton_Clicked(sender, e) /// <summary> /// 길게 누른 경우 진동시키기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void longPressButton_Clicked(object sender, EventArgs e) { HapticFeedback.Default.Perform(HapticFeedbackType.LongPress); } #endregion } |
※ 프리뷰
■ Location 클래스의 CalculateDistance 메소드를 사용해 거리를 계산하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 |
Location location1 = new Location(42.358056, -71.063611); // 보스턴 Location location2 = new Location(37.783333, -122.416667); // 샌프란시스코 double distance = Location.CalculateDistance(location1, location2, DistanceUnits.Miles); |
■ IGeolocation 인터페이스의 GetLocationAsync 메소드를 사용해 GPS 위치를 구하는 방법을 보여준다. (ANDROID) ▶ Platforms/Andriod/Resources/AndroidManifest.xml
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> </manifest> |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <StackLayout HorizontalOptions="Center" VerticalOptions="Center" Spacing="10"> <Button x:Name="getbutton" HorizontalOptions="Center" Text="GPS 위치 구하기" /> <Label x:Name="messageLabel" HorizontalOptions="Center" /> </StackLayout> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.getbutton.Clicked += getbutton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region GPS 위치 구하기 버튼 클릭시 처리하기 - getbutton_Clicked(sender, e) /// <summary> /// GPS 위치 구하기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private async void getbutton_Clicked(object sender, EventArgs e) { try { GeolocationRequest request = new GeolocationRequest(GeolocationAccuracy.Medium); Location location = await Geolocation.Default.GetLocationAsync(request); if(location != null) { this.messageLabel.Text = $"위도 : {location.Latitude}\n경도 : {location.Longitude}\n고도 : {location.Altitude}"; } } catch(FeatureNotSupportedException) { await DisplayAlert("ERROR", "지원되지 않은 기능입니다.", "확인"); } catch(FeatureNotEnabledException) { await DisplayAlert("ERROR", "비활성된 기능입니다.", "확인"); } catch(PermissionException) { await DisplayAlert("ERROR", "권한이 설정되지 않았습니다.", "확인"); } catch(Exception) { await DisplayAlert("ERROR", "실행시 에러가 발생했습니다.", "확인"); } } #endregion } |
TestProject.zip
■ IGeolocation 인터페이스의 GetLastKnownLocationAsync 메소드를 사용해 가장 최근 GPS 위치를 구하는 방법을 보여준다. (ANDROID) ▶ Platforms/Andriod/Resources/AndroidManifest.xml
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> </manifest> |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <StackLayout HorizontalOptions="Center" VerticalOptions="Center" Spacing="10"> <Button x:Name="getbutton" HorizontalOptions="Center" Text="GPS 위치 구하기" /> <Label x:Name="messageLabel" HorizontalOptions="Center" /> </StackLayout> </ContentPage> |
▶ MainPage.xaml.cs
■ IFlashlight 인터페이스의 TurnOnAsync/TurnOffAsync 메소드를 사용해 플래시를 켜고 끄는 방법을 보여준다. ▶ Platforms/Android/AndroidManifest.xml
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.FLASHLIGHT" /> </manifest> |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <StackLayout HorizontalOptions="Center" VerticalOptions="Center" Orientation="Horizontal"> <Label VerticalOptions="Center" FontSize="24" FontAttributes="Bold" Text="플래시" /> <Switch x:Name="flashSwitch" Margin="10,0,0,0" VerticalOptions="Center" /> </StackLayout> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.flashSwitch.Toggled += flashSwitch_Toggled; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 플래시 스위치 토글시 처리하기 - flashSwitch_Toggled(sender, e) /// <summary> /// 플래시 스위치 토글시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private async void flashSwitch_Toggled(object sender, ToggledEventArgs e) { try { if(e.Value) { await Flashlight.Default.TurnOnAsync(); } else { await Flashlight.Default.TurnOffAsync(); } } catch(FeatureNotSupportedException) { await DisplayAlert("ERROR", "해당 기능을 지원하지 않습니다.", "확인"); } catch(PermissionException) { await DisplayAlert("ERROR", "해당 기능의 권한이 없습니다.", "확인"); } catch(Exception) { } } #endregion } |
TestProject.zip
■ Magnetometer 클래스의 ReadingChanged 정적 이벤트를 사용해 지구 자기장에 대한 장치 방향을 구하는 방법을 보여준다. ▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Grid RowDefinitions="*,Auto,10,Auto,*"> <Button x:Name="startButton" Grid.Row="1" HorizontalOptions="Center" WidthRequest="100" Text="시작" /> <Label x:Name="label" Grid.Row="3" HorizontalOptions="Center" /> </Grid> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); Magnetometer.ReadingChanged += magnetometer_ReadingChanged; this.startButton.Clicked += startButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 자력계 읽기 변경시 처리하기 - magnetometer_ReadingChanged(sender, e) /// <summary> /// 자력계 읽기 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void magnetometer_ReadingChanged(object sender, MagnetometerChangedEventArgs e) { this.label.Text = $"자력계 : {e.Reading}"; } #endregion #region 시작 버튼 클릭시 처리하기 - startButton_Clicked(sender, e) /// <summary> /// 시작 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void startButton_Clicked(object sender, EventArgs e) { if(Magnetometer.IsMonitoring) { Magnetometer.Stop(); this.startButton.Text = "시작"; this.label.Text = string.Empty; } else { this.startButton.Text = "중단"; Magnetometer.Start(SensorSpeed.UI); } } #endregion } |
TestProject.zip
■ Gyroscope 클래스의 ReadingChanged 정적 이벤트를 사용해 장치 3차원 회전 각도를 구하는 방법을 보여준다. ▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Grid RowDefinitions="*,Auto,10,Auto,*"> <Button x:Name="startButton" Grid.Row="1" HorizontalOptions="Center" WidthRequest="100" Text="시작" /> <Label x:Name="label" Grid.Row="3" HorizontalOptions="Center" /> </Grid> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); Gyroscope.ReadingChanged += gyroscope_ReadingChanged; this.startButton.Clicked += startButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 자이로스코프 읽기 변경시 처리하기 - gyroscope_ReadingChanged(sender, e) /// <summary> /// 자이로스코프 읽기 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void gyroscope_ReadingChanged(object sender, GyroscopeChangedEventArgs e) { this.label.Text = $"자이로스코프 : {e.Reading}"; } #endregion #region 시작 버튼 클릭시 처리하기 - startButton_Clicked(sender, e) /// <summary> /// 시작 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void startButton_Clicked(object sender, EventArgs e) { if(Gyroscope.IsMonitoring) { Gyroscope.Stop(); this.startButton.Text = "시작"; this.label.Text = string.Empty; } else { this.startButton.Text = "중단"; Gyroscope.Start(SensorSpeed.UI); } } #endregion } |
TestProject.zip
■ Accelerometer 클래스의 ShakeDetected 정적 이벤트를 사용해 흔들기를 탐지하는 방법을 보여준다. ▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Grid RowDefinitions="*,Auto,10,Auto,*"> <Button x:Name="startButton" Grid.Row="1" HorizontalOptions="Center" WidthRequest="100" Text="시작" /> <Label x:Name="label" Grid.Row="3" HorizontalOptions="Center" /> </Grid> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); Accelerometer.ShakeDetected += accelerometer_ShakeDetected; this.startButton.Clicked += startButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 가속도계 흔들기 탐지시 처리하기 - accelerometer_ShakeDetected(sender, e) /// <summary> /// 가속도계 흔들기 탐지시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void accelerometer_ShakeDetected(object sender, EventArgs e) { this.label.Text = $"[{DateTime.Now.ToString("HH:mm:ss")}] 휴대폰을 흔들었습니다."; } #endregion #region 시작 버튼 클릭시 처리하기 - startButton_Clicked(sender, e) /// <summary> /// 시작 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void startButton_Clicked(object sender, EventArgs e) { if(Accelerometer.IsMonitoring) { Accelerometer.Stop(); this.startButton.Text = "시작"; this.label.Text = string.Empty; } else { this.startButton.Text = "중단"; Accelerometer.Start(SensorSpeed.UI); } } #endregion } |
TestProject.zip
■ Barometer 클래스의 ReadingChanged 정적 이벤트를 사용해 기압을 구하는 방법을 보여준다. ▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Grid RowDefinitions="*,Auto,10,Auto,*"> <Button x:Name="startButton" Grid.Row="1" HorizontalOptions="Center" WidthRequest="100" Text="시작" /> <Label x:Name="label" Grid.Row="3" HorizontalOptions="Center" /> </Grid> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); Barometer.ReadingChanged += barometer_ReadingChanged; this.startButton.Clicked += startButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 기압계 읽기 변경시 처리하기 - barometer_ReadingChanged(sender, e) /// <summary> /// 기압계 읽기 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void barometer_ReadingChanged(object sender, BarometerChangedEventArgs e) { BarometerData data = e.Reading; this.label.Text = $"기압(헥토파스칼) : {data.PressureInHectopascals}"; } #endregion #region 시작 버튼 클릭시 처리하기 - startButton_Clicked(sender, e) /// <summary> /// 시작 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void startButton_Clicked(object sender, EventArgs e) { if(Barometer.IsMonitoring) { Barometer.Stop(); this.startButton.Text = "시작"; this.label.Text = string.Empty; } else { this.startButton.Text = "중단"; Barometer.Start(SensorSpeed.UI); } } #endregion } |
TestProject.zip
■ Compass 클래스의 ReadingChanged 정적 이벤트를 사용해 나침반 방향을 구하는 방법을 보여준다. ▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Grid RowDefinitions="*,Auto,10,Auto,*"> <Button x:Name="startButton" Grid.Row="1" HorizontalOptions="Center" WidthRequest="100" Text="시작" /> <Label x:Name="label" Grid.Row="3" HorizontalOptions="Center" /> </Grid> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); Compass.ReadingChanged += compass_ReadingChanged; this.startButton.Clicked += startButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 나침반 읽기 변경시 처리하기 - compass_ReadingChanged(sender, e) /// <summary> /// 나침반 읽기 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void compass_ReadingChanged(object sender, CompassChangedEventArgs e) { CompassData data = e.Reading; this.label.Text = $"북쪽 방향 : {data.HeadingMagneticNorth}도"; } #endregion #region 시작 버튼 클릭시 처리하기 - startButton_Clicked(sender, e) /// <summary> /// 시작 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void startButton_Clicked(object sender, EventArgs e) { if(Compass.IsMonitoring) { Compass.Stop(); this.startButton.Text = "시작"; this.label.Text = string.Empty; } else { this.startButton.Text = "중단"; Compass.Start(SensorSpeed.UI, true); } } #endregion } |
TestProject.zip
■ Vibration 클래스의 Vibrate 정적 메소드를 사용해 휴대폰을 진동시키는 방법을 보여준다. (ANDRIOD) ▶ Platforms/Andriod/Resources/AndroidManifest.xml
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.VIBRATE" /> </manifest> |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Button x:Name="vibrationButton" HorizontalOptions="Center" VerticalOptions="Center" WidthRequest="100" Text="진동" /> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.vibrationButton.Clicked += vibrationButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 진동 버튼 클릭시 처리하기 - vibrationButton_Clicked(sender, e) /// <summary> /// 진동 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void vibrationButton_Clicked(object sender, EventArgs e) { Vibration.Vibrate(); // 500밀리초 TimeSpan vibrationTimeSpan = TimeSpan.FromMilliseconds(500); Vibration.Vibrate(vibrationTimeSpan); } #endregion } |
TestProject.zip
■ OrientationSensor 클래스의 ReadingChanged 정적 이벤트를 사용해 방향을 구하는 방법을 보여준다. ▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Grid RowDefinitions="*,Auto,10,Auto,*"> <Button x:Name="startButton" Grid.Row="1" HorizontalOptions="Center" WidthRequest="100" Text="시작" /> <Label x:Name="label" Grid.Row="3" HorizontalOptions="Center" /> </Grid> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); OrientationSensor.ReadingChanged += orientationSensor_ReadingChanged; this.startButton.Clicked += startButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 방향 센서 읽기 변경시 처리하기 - orientationSensor_ReadingChanged(sender, e) /// <summary> /// 방향 센서 읽기 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void orientationSensor_ReadingChanged(object sender, OrientationSensorChangedEventArgs e) { OrientationSensorData data = e.Reading; this.label.Text = $"X : {data.Orientation.X}\nY : {data.Orientation.Y}\nZ : {data.Orientation.Z}\nW : {data.Orientation.W}"; } #endregion #region 시작 버튼 클릭시 처리하기 - startButton_Clicked(sender, e) /// <summary> /// 시작 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void startButton_Clicked(object sender, EventArgs e) { if(OrientationSensor.IsMonitoring) { OrientationSensor.Stop(); this.startButton.Text = "시작"; this.label.Text = string.Empty; } else { this.startButton.Text = "중단"; OrientationSensor.Start(SensorSpeed.UI); } } #endregion } |
TestProject.zip
■ Accelerometer 클래스의 ReadingChanged 정적 이벤트를 사용해 가속도를 구하는 방법을 보여준다. ▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <Grid RowDefinitions="*,Auto,10,Auto,*"> <Button x:Name="startButton" Grid.Row="1" HorizontalOptions="Center" WidthRequest="100" Text="시작" /> <Label x:Name="label" Grid.Row="3" HorizontalOptions="Center" /> </Grid> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); Accelerometer.ReadingChanged += accelerometer_ReadingChanged; this.startButton.Clicked += startButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 가속도계 읽기 변경시 처리하기 - accelerometer_ReadingChanged(sender, e) /// <summary> /// 가속도계 읽기 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void accelerometer_ReadingChanged(object sender, AccelerometerChangedEventArgs e) { AccelerometerData data = e.Reading; this.label.Text = $"X축 : {data.Acceleration.X}\nY축 : {data.Acceleration.Y}\nZ축 : {data.Acceleration.Z}"; } #endregion #region 시작 버튼 클릭시 처리하기 - startButton_Clicked(sender, e) /// <summary> /// 시작 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void startButton_Clicked(object sender, EventArgs e) { if(Accelerometer.IsMonitoring) { Accelerometer.Stop(); this.startButton.Text = "시작"; this.label.Text = string.Empty; } else { this.startButton.Text = "중단"; Accelerometer.Start(SensorSpeed.UI); } } #endregion } |
TestProject.zip
■ Geolocation 클래스의 GetLocationAsync 정적 메소드를 사용해 GPS 위치를 구하는 방법을 보여준다. (ANDROID) ▶ Platforms/Andriod/Resources/AndroidManifest.xml
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> </manifest> |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <StackLayout HorizontalOptions="Center" VerticalOptions="Center" Spacing="10"> <Button x:Name="getButton" HorizontalOptions="Center" Text="GPS 위치 구하기" /> <Label x:Name="messageLabel" HorizontalOptions="Center" /> </StackLayout> </ContentPage> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.getButton.Clicked += getButton_Clicked; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region GPS 위치 구하기 버튼 클릭시 처리하기 - getButton_Clicked(sender, e) /// <summary> /// GPS 위치 구하기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private async void getButton_Clicked(object sender, EventArgs e) { Location location = await Geolocation.GetLocationAsync(); this.messageLabel.Text = $"위도 : {location.Latitude}\n경도 : {location.Longitude}"; } #endregion } |
■ IFingerprint 인터페이스의 AuthenticateAsync 메소드를 사용해 지문을 인증하는 방법을 보여준다. (ANDROID) ▶ Platforms/Android/AndroidManifest.xml
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.USE_BIOMETRIC" /> </manifest> |
▶ Platforms/Android/MainActivity.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
using Android.App; using Android.Content.PM; using Android.OS; using Plugin.Fingerprint; namespace TestProject; /// <summary> /// 메인 액티비티 /// </summary> [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] public class MainActivity : MauiAppCompatActivity { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 생성시 처리하기 - OnCreate(savedInstanceState) /// <summary> /// 생성시 처리하기 /// </summary> /// <param name="savedInstanceState">저장 인스턴스 상태</param> protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); CrossFingerprint.SetCurrentActivityResolver(() => this); } #endregion } |
▶ MauiProgram.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
using Plugin.Fingerprint; using Plugin.Fingerprint.Abstractions; namespace TestProject; /// <summary> /// MAUI 프로그램 /// </summary> public static class MauiProgram { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region MAUI 앱 생성하기 - CreateMauiApp() /// <summary> /// MAUI 앱 생성하기 /// </summary> /// <returns>MAUI 앱</returns> public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp<App>() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf" , "OpenSansRegular" ); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); } ); builder.Services.AddSingleton(typeof(IFingerprint), CrossFingerprint.Current); return builder.Build(); } #endregion } |
▶ MainPage.xaml
■ Process 클래스의 Start 정적 메소드를 사용해 장치 및 프린터 대화 상자를 표시하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
using System.Diagnostics; ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd", "/C control printers"); processStartInfo.WindowStyle = ProcessWindowStyle.Hidden; Process process = new Process(); process.StartInfo = processStartInfo; process.Start(); |
■ Process 클래스의 Start 정적 메소드를 사용해 장치 및 프린터 대화 상자를 표시하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 |
using System.Diagnostics; Process.Start("cmd", "/C control printers"); |
■ 카메라 정보를 조회하는 방법을 보여준다. ▶ Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
using System; using System.Management; namespace TestProject { /// <summary> /// 프로그램 /// </summary> class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> private static void Main() { string cameraName = "USB2.0 PC CAMERA"; string queryString1 = "Select * From Win32_USBControllerDevice"; using(ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(queryString1)) { ManagementObjectCollection collection1 = searcher1.Get(); foreach(ManagementBaseObject item1 in collection1) { string dependent = item1.GetPropertyValue("Dependent") as string; string deviceID = (dependent.Split(new string[] { "DeviceID=" }, 2, StringSplitOptions.None)[1]); string queryString2 = $"Select * From Win32_PnpEntity Where PNPClass = 'Camera' And PNPDeviceID = {deviceID}"; using(ManagementObjectSearcher searcher2 = new ManagementObjectSearcher(queryString2)) { ManagementObjectCollection collection2 = searcher2.Get(); foreach(ManagementBaseObject item2 in collection2) { string caption = item2.GetPropertyValue("Caption") as string; if(caption != cameraName) { continue; } foreach(PropertyData propertyData in item2.Properties) { Console.WriteLine($"{propertyData.Name} : {propertyData.Value}"); } Console.WriteLine(); } collection2.Dispose(); } } collection1.Dispose(); } } #endregion } } |
TestProject.zip
■ Process 클래스의 Start 정적 메소드를 사용해 장치 및 프린터 대화 상자를 표시하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 |
using System.Diagnostics; using System.IO; string controlPanelFilePath = Path.Combine ( Environment.GetFolderPath(Environment.SpecialFolder.System), "control.exe" ); Process.Start(controlPanelFilePath, "/name Microsoft.DevicesAndPrinters"); |
■ Get-CimInstance 명령을 사용해 카메라 인스턴스 ID를 구하는 방법을 보여준다. ▶ 실행 명령
1 2 3 4 5 |
$id = (Get-CimInstance -Class Win32_PnpEntity | where pnpclass -match 'camera').pnpDeviceID $id |
■ wmic 명령을 사용해 카메라의 물리적 장치 객체명(Physical Device Object Name)을 구하는 방법을 보여준다. ▶ 실행 명령
1 2 3 4 5 |
wmic path Win32_PnPSignedDriver where "FriendlyName LIKE '%camera%'" get DeviceName,FriendlyName,PDO wmic path Win32_PnPSignedDriver where "DeviceName = 'USB Video Device' and PDO LIKE '\\Device\\%'" get DeviceName,FriendlyName,PDO |