{"id":641,"date":"2023-01-04T18:02:16","date_gmt":"2023-01-04T18:02:16","guid":{"rendered":"https:\/\/learnmobiledevelopment.com\/?p=641"},"modified":"2023-01-18T16:18:02","modified_gmt":"2023-01-18T16:18:02","slug":"get-device-and-app-informations-in-maui","status":"publish","type":"post","link":"https:\/\/learnmobiledevelopment.com\/index.php\/2023\/01\/04\/get-device-and-app-informations-in-maui\/","title":{"rendered":"How to get Device and App Informations in MAUI"},"content":{"rendered":"\n<p>As a mobile apps developer, sometimes we need device and app information like device Model, Manufacturer, OS Version, App Version, Package Name etc. to perform some actions. That\u2019s why in this article i am going to show you how to get device and app Informations in MAUI.<\/p>\n\n\n\n<p style=\"font-size:25px\"><strong>Let&#8217;s Start<\/strong><\/p>\n\n\n\n<p>In this article you will see :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>What is DeviceInfo?<\/strong><\/li>\n\n\n\n<li><strong>What is AppInfo?<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>What is DeviceInfo?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>DeviceInfo<\/strong> is a class in MAUI that allows us to get device information on which our App is running on.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Device information that we can get using DeviceInfo class :&nbsp;<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><em>Model<\/em><\/strong> &#8211; It provides us device model. (<strong><em>eg : iPhone13<\/em><\/strong>)<\/li>\n\n\n\n<li><strong><em>Manufacturer<\/em><\/strong> &#8211; It provides us device Manufacturer. (<strong><em>eg : Apple<\/em><\/strong>)<\/li>\n\n\n\n<li><strong><em>Name<\/em><\/strong> &#8211; It provides us device name. (<strong><em>eg : Alamgeer&#8217;s iPhone<\/em><\/strong>)<\/li>\n\n\n\n<li><strong><em>VersionString<\/em><\/strong> -It provides us os version. (<strong><em>eg : 16.2<\/em><\/strong>)<\/li>\n\n\n\n<li><strong><em>Idiom<\/em><\/strong> &#8211; It provides us types of device on which the application is running on. It can be <em><strong>Phone<\/strong><\/em>, <strong><em>Tablet<\/em><\/strong>, <strong><em>Desktop<\/em><\/strong>, <strong><em>TV<\/em><\/strong>, <strong><em>Watch<\/em><\/strong> etc.<\/li>\n\n\n\n<li><strong><em>Platform<\/em><\/strong> &#8211; It provides us device platform. It can be <strong><em>Android<\/em><\/strong>, <strong><em>iOS<\/em><\/strong>, <strong><em>WinUI<\/em><\/strong>, <strong><em>MacCatalyst<\/em><\/strong>, <strong><em>Tizen<\/em><\/strong> etc.<\/li>\n\n\n\n<li><strong><em>DeviceType<\/em><\/strong> &#8211; It provides us types of device and identify if we are running the application on an <strong><em>emulator<\/em><\/strong> or <strong><em>physical device<\/em><\/strong>.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>What is AppInfo?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>AppInfo<\/strong> is a class in MAUI that allows us to get app Information.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\"><strong>App information that we can get using <strong>AppInfo<\/strong> class :&nbsp;<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><em>Name<\/em><\/strong> &#8211; It provides us name of the application. (<strong><em>eg : MAUIDeviceAndAppInfoSample<\/em><\/strong>)<\/li>\n\n\n\n<li><strong><em>PackageName<\/em><\/strong> &#8211; It provides us package name or identifier of the application. (<strong><em>eg : com.companyname.mauideviceandappinfosample<\/em><\/strong>)<\/li>\n\n\n\n<li><strong><em>VersionString<\/em><\/strong> &#8211; It provides us the application version. (<strong><em>eg : 1.0<\/em><\/strong>)<\/li>\n\n\n\n<li><strong><em>BuildString<\/em><\/strong> &#8211; It provides us the build number of the version. (<strong>eg : 1<\/strong>)<\/li>\n\n\n\n<li><strong><em>RequestedLayoutDirection<\/em><\/strong> &#8211; It provides the current requested layout direction. (<strong><em>eg : LeftToRight<\/em><\/strong>)<\/li>\n\n\n\n<li><strong><em>RequestedTheme<\/em><\/strong> &#8211; It provides the current requested theme by the system for your application. (<strong><em>eg : Light<\/em><\/strong>)<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Let&#8217;s move to the coding part<\/strong> <strong>!!<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Setting up the UI <\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>1 &#8211; Create a MainPage.xaml<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\" encoding=\"utf-8\" ?>\n&lt;ContentPage\n    x:Class=\"MAUIDeviceAndAppInfoSample.MainPage\"\n    xmlns=\"http:\/\/schemas.microsoft.com\/dotnet\/2021\/maui\"\n    xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2009\/xaml\"\n    BackgroundColor=\"Black\">\n\n    &lt;ScrollView>\n        &lt;VerticalStackLayout\n            Padding=\"20\"\n            BackgroundColor=\"White\"\n            Spacing=\"10\">\n\n            &lt;Label\n                FontAttributes=\"Bold\"\n                FontSize=\"22\"\n                Text=\"Device Informtaion\" \/>\n\n            &lt;Label x:Name=\"LblDeviceInfo\" FontSize=\"18\" \/>\n\n            &lt;Label\n                FontAttributes=\"Bold\"\n                FontSize=\"22\"\n                Text=\"App Informtaion\" \/>\n\n            &lt;Label x:Name=\"LblAppInfo\" FontSize=\"18\" \/>\n\n        &lt;\/VerticalStackLayout>\n    &lt;\/ScrollView>\n\n&lt;\/ContentPage><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>2 &#8211; MainPage.xaml.cs<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using System.Text;\n\nnamespace MAUIDeviceAndAppInfoSample;\n\npublic partial class MainPage : ContentPage\n{\n    public MainPage()\n    {\n        InitializeComponent();\n        LblDeviceInfo.Text = GetDeviceInfo();\n        LblAppInfo.Text = GetAppInfo();\n    }\n\n    private string GetDeviceInfo()\n    {\n        return new StringBuilder()\n            .AppendLine($\"Model : {DeviceInfo.Current.Model}\")\n            .AppendLine($\"Manufacturer : {DeviceInfo.Current.Manufacturer}\")\n            .AppendLine($\"Name : {DeviceInfo.Name}\")\n            .AppendLine($\"OS Version : {DeviceInfo.VersionString}\")\n            .AppendLine($\"Refresh Rate : {DeviceInfo.Current}\")\n            .AppendLine($\"Idiom : {DeviceInfo.Current.Idiom}\")\n            .AppendLine($\"Platform : {DeviceInfo.Current.Platform}\")\n            .AppendLine($\"Device Type : {DeviceInfo.Current.DeviceType}\").ToString();\n    }\n\n    private string GetAppInfo()\n    {\n        return new StringBuilder()\n           .AppendLine($\"Name : {AppInfo.Current.Name}\")\n           .AppendLine($\"Package : {AppInfo.Current.PackageName}\")\n           .AppendLine($\"Version : {AppInfo.Current.VersionString}\")\n           .AppendLine($\"Build : {AppInfo.Current.BuildString}\")\n           .AppendLine($\"LayoutDirection : {AppInfo.RequestedLayoutDirection}\")\n           .AppendLine($\"Theme : {AppInfo.RequestedTheme}\").ToString();\n    }\n}<\/pre>\n\n\n\n<p>That\u2019s all for now!<\/p>\n\n\n\n<p>You can check the full source code&nbsp;<strong><a href=\"https:\/\/github.com\/Alam-Ashraf\/MAUIDeviceAndAppInfoSample\" target=\"_blank\" rel=\"noopener\" title=\"\">here<\/a>.<\/strong><\/p>\n\n\n\n<p>Happy Coding! <strong>\ud83d\ude00\u00a0<\/strong><\/p>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>You may also like<\/strong><\/p>\n\n\n\n<div class=\"wp-block-group is-content-justification-space-between is-nowrap is-layout-flex wp-container-core-group-is-layout-0dfbf163 wp-block-group-is-layout-flex\">\n<div class=\"wp-block-group is-vertical is-content-justification-center is-layout-flex wp-container-core-group-is-layout-4b2eccd6 wp-block-group-is-layout-flex\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/learnmobiledevelopment.com\/index.php\/2022\/12\/11\/statecontainer-in-maui\/\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/StateContainerInMAUI-1024x789.png\" alt=\"StateContainer In MAUI\" class=\"wp-image-481\" width=\"512\" height=\"395\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/StateContainerInMAUI-1024x789.png 1024w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/StateContainerInMAUI-300x231.png 300w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/StateContainerInMAUI-768x592.png 768w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/StateContainerInMAUI-850x655.png 850w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/StateContainerInMAUI.png 1176w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\">How to use StateContainer in MAUI<\/p>\n<\/div>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-group is-vertical is-content-justification-center is-layout-flex wp-container-core-group-is-layout-4b2eccd6 wp-block-group-is-layout-flex\">\n<div class=\"wp-block-group is-vertical is-content-justification-center is-layout-flex wp-container-core-group-is-layout-4b2eccd6 wp-block-group-is-layout-flex\"><div class=\"wp-block-image is-style-default\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/learnmobiledevelopment.com\/index.php\/2022\/12\/03\/expander-in-maui\/\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/Expander-in-Dot-Net-MAUI-1024x624.png\" alt=\"Expander in MAUI\" class=\"wp-image-435\" width=\"512\" height=\"312\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/Expander-in-Dot-Net-MAUI-1024x624.png 1024w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/Expander-in-Dot-Net-MAUI-300x183.png 300w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/Expander-in-Dot-Net-MAUI-768x468.png 768w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/Expander-in-Dot-Net-MAUI-850x518.png 850w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/Expander-in-Dot-Net-MAUI.png 1260w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\">How to use Expander in MAUI<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>As a mobile apps developer, sometimes we need device and app information like device Model, Manufacturer, OS Version, App Version, Package Name etc. to perform some actions. That\u2019s why in this article i am going to show you how to get device and app Informations in MAUI. Let&#8217;s Start In this article you will see&#8230;<\/p>\n","protected":false},"author":1,"featured_media":653,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[49,47,48],"class_list":["post-641","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnetmaui","tag-getting-app-info","tag-getting-device-app-info-in-maui","tag-getting-device-info"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/comments?post=641"}],"version-history":[{"count":15,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/641\/revisions"}],"predecessor-version":[{"id":742,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/641\/revisions\/742"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/media\/653"}],"wp:attachment":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/media?parent=641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/categories?post=641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/tags?post=641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}