Android Question Device ID

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Hi

When installing app in debug mode the ide shows the device id

1. Is this a unique ID?
2. How can I get this ID from my app?

Thanks
 

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
update:

i'm using this code to get the DeviceID

DEviceID = P.GetSettings("android_id").ToUpperCase
Log($"DeviceID: ${DEviceID}"$)

the results on 2 different devices are:

Device #1
Logger connected to: AHK7N17124010657
DeviceID: 4ADBE0CE7317CDCE

Device #2
Logger connected to: R5CT30R2EXN
DeviceID: A7D4C18FCCE5D7BF

the Logger is the ID the IDE is showing when installing to the device
the DeviceID is what i Get

which one is the real device id?
is it unique?
why the difference?
if the Logger is the right one - how do i obtain it?

thanks
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
I am not sure but you can get that in B4A Bridge source code.

FYI Advertising ID is most reliable
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
I am not sure but you can get that in B4A Bridge source code.

FYI Advertising ID is most reliable
thanks

as far as i learned advertising id can be reset by the phone holder so it is not what i need

the main issue now is what is the difference between the 2 IDs and which one is unique

i couldn't find anywhere any info on the serial id or logger id other than what i see on my IDE
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Unique device identifiers have been discussed in this forum many, many times - you can find example threads quite easily. If you are using recent Android versions then there is no unique identifier that will identify a specific device. The advertising id is often suggested as the best option available, but as you say this can be changed by the User. Usually user online registration with a user identifier and password is suggested as the only sure path.

If you have found something new then that would be very interesting, and surprising.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
I can't use username password due the nature of my app, so I use a mechanism where I need the device id.
I now have it.
The question is how unique is it?

Advertising id is not good for my needs

Previously I used imei but seems Google blocked it so I can't grab it anymore

If device id is unique so I have my solution

Otherwise, how can I get the serial ID like the B4A ide gets it when it installs using USB debugging?

I need a solid solution for identifying the device uniquely
 
Upvote 0

Addo

Well-Known Member
Licensed User
Longtime User
Honestly you shouldn't rely on device idenfiers in your app, since every single identfier can be changed or gets faked.
Those ID are easy to be faked using third-party applications.
Android id
Mediadrm id
Advertising id
Even storing file with a unique ID in external storage are discoverable and easy to delete. Although Google makes it harder to identify devices.
The most stable and secure method is forcing the user to register to your app and store there special ID that you can generate easily on your backend and validate each login to identify the user.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Honestly you shouldn't rely on device idenfiers in your app, since every single identfier can be changed or gets faked.
Those ID are easy to be faked using third-party applications.
Android id
Mediadrm id
Advertising id
Even storing file with a unique ID in external storage are discoverable and easy to delete. Although Google makes it harder to identify devices.
The most stable and secure method is forcing the user to register to your app and store there special ID that you can generate easily on your backend and validate each login to identify the user.
thank you for this
my app uses a remote license so the user fills his details and it sends it to the server wit5h the id
then when he runs the app the license is retrieved using the id
if he changes the id he will get no license and the app will run as demo
since it is his tool to get payments he wont dare to mess with it
therefore i need the id to be unique i don't care if the user changed it as he will then have to pay again for a new license :)
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
Well, I think it's unfair to your users if they should lose their device or change their device or reset their device, to pay for another license.

I will suggest, even if you are using their device IDs, you should add a registration system attached to the ID

In the case that the login credentials do not match the device, you prompt if the user changed their device and is willing for the old device to be deleted.
If yes, then you logout from all devices, and even turn them to demo, and add the new device ID added to the credentials.

In this way, the user gets to continue using his license on a new device. My thoughts
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Well, I think it's unfair to your users if they should lose their device or change their device or reset their device, to pay for another license.

I will suggest, even if you are using their device IDs, you should add a registration system attached to the ID

In the case that the login credentials do not match the device, you prompt if the user changed their device and is willing for the old device to be deleted.
If yes, then you logout from all devices, and even turn them to demo, and add the new device ID added to the credentials.

In this way, the user gets to continue using his license on a new device. My thoughts
we use something like that - if he changes the id the license will move to the new one. if he wants to retain the old one meaning 2 licemses then he must pay
the logic is license per device
 
Upvote 0

Bladimir Silva Toro

Active Member
Licensed User
Longtime User
Hello @Zeev Goldstein

Use DeviceID with the email and/or username with that you can control your licenses.

When you use DeviceID, that identifier changes when a hardware reset to the device is performed, but when the user, at the time of validating their license, will realize that something happened and will call you, it would only be that you delete that old identification from your database and have the user re-register that new ID.

It is what I do with all my users and it works perfectly.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Hello @Zeev Goldstein

Use DeviceID with the email and/or username with that you can control your licenses.

When you use DeviceID, that identifier changes when a hardware reset to the device is performed, but when the user, at the time of validating their license, will realize that something happened and will call you, it would only be that you delete that old identification from your database and have the user re-register that new ID.

It is what I do with all my users and it works perfectly.
Brilliant idea! Adding the mail I like it.

But I need to know is the device id is unique or not?

And does it change on phone reboot or factory reset?

That I think is critical

Finall - any way to grab imei as was possible in earlier versions of Android?
This will be the absolute best

Thanks
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
MAC address
Standard function now is that the MAC address is periodically changed by the modern version of mobile OS, by default.
And Google made many and going on to prevent getting really unique device id (IMEI, phone number).
 
Upvote 0

Addo

Well-Known Member
Licensed User
Longtime User
If you have no problem with keeping the identifiers in your app login then the most accurate record is
Mediadrm id
Advertising id

Mediadrm id may not be available on all devices and if it's not available you should get advertising id.
You can look for this github for examples

 
Upvote 0

Bladimir Silva Toro

Active Member
Licensed User
Longtime User
Brilliant idea! Adding the mail I like it.

But I need to know is the device id is unique or not?
Hello @Zeev Goldstein

The DeviceID generates a unique identifier for each device (note that if it is used with an emulator it always generates the same ID)
And does it change on phone reboot or factory reset?
The generated ID changes when a hardware or factory reset is done, but if you handle it with email you can control your license without problems.
That I think is critical

Finall - any way to grab imei as was possible in earlier versions of Android?
This will be the absolute best

Thanks
As for the IMEI, it could be consulted in the old versions of Android but later they removed it due to security problems.

Look at this code in B4A

B4X:
Dim Api AsInt

 Api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")

  If Api < 9Then
    'old devices (Versions below Android 9)
    id= p.GetSettings("android_id")
  Else
    'new devices (Versions Equal or higher Android 9)
    id= r.GetStaticField("android.os.Build", "SERIAL")
    If id.ToLowerCase = "unknown"Then id= p.GetSettings("android_id")
  EndIf

  Return id

End Sub
 
Last edited:
Upvote 0

ilan

Expert
Licensed User
Longtime User
you can try to use the IMEI that is unique for each device:


 
Upvote 0
Top