MAUI Unique Device Identifier ID

Etien Ducka 30 Reputation points
2024-05-15T10:42:58.6333333+00:00

I am looking for a Unique Device Identifier ID for Android and iOS.

Is there any code for that ?

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

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 69,921 Reputation points Microsoft Vendor
    2024-05-16T02:46:12.0633333+00:00

    Hello,

    You can get Device Id by Android.Provider.Settings.Secure for Android and UIKit.UIDevice.CurrentDevice.IdentifierForVendor for iOS.

    If you want to invoke it in the MAUI directly, please use Conditional compilation

    You can refer to the following code.

    #if ANDROID
    
                string deviceID = Android.Provider.Settings.Secure.GetString(Platform.CurrentActivity.ContentResolver, Android.Provider.Settings.Secure.AndroidId);
     
    #elif IOS
                string deviceID = UIKit.UIDevice.CurrentDevice.IdentifierForVendor.ToString();
    #endif
    

    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.