Unique ID of MAUI device

Wheelstring 190 Reputation points
2025-02-20T10:00:22.5+00:00

Hello IT gurus

I need some unique identifier of MAUI device (platforms: iPhone/Windows/Android/Tizen/MacCatalyst...) like MAC address of device, whatever...

I want answer on this question:

Is it the first (self) app instalation on this device? Yes/No (True/False)

I need solve situation: install(first)-uninstall-install(second)-uninstall-install(second..and..more..)

Thank for ideas, hints!

W

Tags: MAUI, iOS, Windows, Android, C#, MacOS, Tizen, App publishing

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,926 Reputation points Volunteer Moderator
    2025-02-21T04:10:36.5333333+00:00

    this is the standard 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
    

    the android id is assigned when the device is first booted, and should remain for the life of the device.

    apple is more privacy conscious, so the IOS version does not support your requirement. it is generated when your app is installed, and shared among your apps, but if they are all removed, then the id is removed. a new install will result in a new id.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Wheelstring 190 Reputation points
    2025-03-20T16:35:28.9766667+00:00

    Hello

    I found solution also for iOS, works good also for Windows (no MAC addresses needed - requied more access rights)... I use SecureStorage class with my own ID (Guid). It is acceptable for my purpose (for testing second instalation...)

    
    			const string KeyID = @"YourSecureStorageKeyID";
    
            	string CrossPlatformID = await SecureStorage.Default.GetAsync(KeyID);
    
    	    	// first installation ?
            	if (CrossPlatformID == null)
                {
    		
    				// generate some your id for example random Guid..
    				Guid g = new Guid();                
    				g = Guid.NewGuid();
                    CrossPlatformID = g.ToString();
    		
    				// store Guid for second instalation 
                    await SecureStorage.Default.SetAsync(KeyID, CrossPlatformID);
    
                }
    			else
    			{
    
    				// second and more installations...
    
    			}
    
    

    regards

    all the best

    W

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.