Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.provider.Settings.Secure.ANDROID_ID returns "android_id"

Tags:

java

android

Is there reason android.provider.Settings.Secure.ANDROID_ID is return the constant "android_id" instead of a 64-bit number as a hex string ?

Description : android.provider.Settings.Secure.ANDROID_ID

  • A 64-bit number (as a hex string) that is randomly generated when the user first sets up the device and should remain constant for the lifetime of the user's device. The value may change if a factory reset is performed on the device.

I am using a Samsung Galaxy S4 w /

 <uses-sdk android:minSdkVersion="13"  android:targetSdkVersion="19" />

Cheers

like image 375
Fabii Avatar asked Oct 07 '14 20:10

Fabii


People also ask

What is secure ANDROID_ID?

Secure Android ID This value is available via Settings. Secure. ANDROID_ID . It's a 64-bit number that should remain constant for the lifetime of a device.

What is Secure settings?

Secure system settings, containing system preferences that applications can read but are not allowed to write. These are for preferences that the user must explicitly modify through the UI of a system app.

What is Ssaid in Android?

Secure. ANDROID_ID or SSAID) has a different value for each app and each user on the device. Developers requiring a device-scoped identifier, should instead use a resettable identifier, such as Advertising ID, giving users more control. Advertising ID also provides a user-facing setting to limit ad tracking.


2 Answers

The android.provider.Settings.Secure.ANDROID_ID is a constant that can be used in android.provider.Settings.Secure.getString(ContentResolver resolver, String name). By default it is set to 'android_id' since that's the name of the property containing the actual Android ID.

Use this code to get the actual id:

String androidId = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID); 
like image 186
Mike Laren Avatar answered Sep 18 '22 05:09

Mike Laren


android.provider.Settings.Secure.ANDROID_ID is to big so use this answer from: https://stackoverflow.com/a/10151694/1815624

new BigInteger(string, 16).longValue()

For any value of someLong:

new BigInteger(Long.toHexString(someLong), 16).longValue() == someLong

In other words, this will return the long you sent into Long.toHexString() for any long value, including negative numbers. It will also accept strings that are bigger than a long and silently return the lower 64 bits of the string as a long. You can just check the string length <= 16 (after trimming whitespace) if you need to be sure the input fits in a long.

https://stackoverflow.com/a/10151694/1815624

like image 43
CrandellWS Avatar answered Sep 20 '22 05:09

CrandellWS