Get Device Unqiue ID

Jassim Al Rahma 1,471 Reputation points


How can I get the device's unique ID in MAUI?


A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,206 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 58,651 Reputation points Microsoft Vendor


    How can I get the device's unique ID in MAUI?

    For iOS, we cannot get the device's unique ID. iOS puts serious restrictions on unique persistent identifiers because of privacy concerns

    For Android, we can use Android.Provider.Settings.Secure to get it.

       public class GetDeviceInfo {  
          public string GetDeviceID() {  
       #if ANDROID  
                var context = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;  
                string id = Secure.GetString(context.ContentResolver, Secure.AndroidId);  
               return id;  
              return "-1";  

    Here is recommended way.

    If you are attempting to do is ensure that when an application is installed, you can get some unique identifier for that installation. If the app is transferred to a new phone, then the identifier is the same, but if it is un-installed then a new identifier is generated. You can generate GUID, then save or get it in your Preferences like following code. This will ensure a unique identifier for the installed application.

       public App()  
               var id = Preferences.Get("my_id", string.Empty);  
               if (string.IsNullOrWhiteSpace(id)) {  
                   id = System.Guid.NewGuid().ToString();  
                   Preferences.Set("my_id", id);  
               MainPage = new AppShell();  

    Best Regards,

    Leon Lu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.