question

ShwetaDeshpande-7668 avatar image
0 Votes"
ShwetaDeshpande-7668 asked JessieZhang-2116 answered

unique ID storage in Xamarin

Hi,
I have a app that should assign a unique number to the device, on which app is installed. So, whenever the app is used, even after many days , it should get that unique ID for the device and extract all the information related to it from the database.

For the unique ID I am have tried creating GUID using System.Guid.NewGuid().
I have two questions,
1. Is there a way of getting GUID assigned using System.Guid function?
2.I want to store it permanently to the app, it should be stored until the app is uninstalled. Which option of system storage should I use?

Thanks in advance for the help.


P.S. I want it to work for phone as well as tab.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered

Hello,


Welcome to our Microsoft Q&A platform!

Is there a way of getting GUID assigned using System.Guid function?

For this, you can refer to Guid.NewGuid Method.

A sample code :

 // Create and display the value of two GUIDs.
 Guid g = Guid.NewGuid();
 Console.WriteLine(g);
 Console.WriteLine(Guid.NewGuid());
    
 // This code example produces a result similar to the following:
    
 // 0f8fad5b-d9cb-469f-a165-70867728950e
 // 7c9e6679-7425-40de-944b-e07fc1f90ae7

I want to store it permanently to the app, it should be stored until the app is uninstalled. Which option of system storage should I use?

For this, you can check document File Storage and Access with Xamarin.Android.
From document Internal vs external storage,we know that

Internal storage refers to the non-volatile memory that Android allocates to the operating system, APKs, and for individual apps. This space is not accessible except by the operating system or apps. Android will allocate a directory in the internal storage partition for each app. When the app is uninstalled, all the files that are kept on internal storage in that directory will also be deleted. Internal storage is best suited for files that are only accessible to the app and that will not be shared with other apps or will have very little value once the app is uninstalled.

So , Internal Storage is recommended and is more suitable for your situation.


Best Regards,


Jessie Zhang


If the response is helpful, please click "Accept Answer" and upvote it.



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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.