Why does AndroidId have a different result between Android and Xamarin

Krammig 6 Reputation points
2022-12-05T05:29:59.957+00:00

I have the need to detect a common factor between two apps, one written in Xamarin and one written in Java (Android Studio), running on a users phone. This will then be sent to a server to identify that phone.

In the good old days the IMEI did the job nicely. However now I am having to use the Device ID, which is fine for the current purpose, but not perfect.

Anyway, using the following statement in Xamarin gives one result, while using the statement that follows this in Android, gives a different result, both on the same phone.

I am currently using the Android code below on several different apps and they all report the same number. It is only when used on Xamarin that the number changes.

Why would this be, why is the Device ID not reported as the same value, and is there a way to identify the DeviceID via both platforms that result in the same output ?

Thanks

Xamarin code - Result is "a70c996e74002942"

var Device_ID = Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId);  

Android Studio code - Result is "702669b2e9a6f7d1"

String Device_ID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID)  
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,261 Reputation points Microsoft Vendor
    2022-12-08T07:02:07.887+00:00

    Hello,

    From ANDROID_ID reference in the Android docs.

    unique to each combination of app-signing key, user, and device

    Because different applications have different app-signing keys, you will get different Android Id.
    If you want to handle the IDs depends greatly on the specific scenario, please refer Android docs: Best practices for unique identifiers

    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.