Android Question Can I still use Android ID?

aeric

Expert
Licensed User
Longtime User
Referring to https://www.b4x.com/android/forum/threads/android-device-unique-id-alternative-to-phoneid.14759/
I also aware that it is recommended to use Advertising Id instead.

Here is the story. I am maintaining an old app which uses the code snippet as mentioned in post #13.
It is a non Google Play app.

B4X:
Sub GetDeviceId As String
Dim p As Phone
Dim id As String
Dim r As Reflector
Dim Api As Int

   Api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")
   If Api < 9 Then
      'Old device
      id= p.GetSettings("android_id")
   Else
      'New device
      id= r.GetStaticField("android.os.Build", "SERIAL")
      If id.ToLowerCase = "unknown" Then id= p.GetSettings("android_id")
   End If
   Return id
End Sub

The app needs to check the device id retrieve from the phone to match a database column to get another device code as a primary key.
The code snippet above seems still working fine for the client's devices. It returns a random code of length 14 or 16 characters long.
When I try to use Advertising Id, it returns a longer id with length of 36 characters.

My question is,
Should I keep using Phone.GetSettings("android_id") or Advertising ID ?

The issue here is since the previous developer didn't provide a Private Sign Key, it seems the device key generated with my own Private Sign Key is Different! It took me few days to find out.
Now, the Admin needs to update all the device ids for all the devices which contains 1300+ of records.
The users have to screenshot the ID on app starts up and send to the Admin. Then he will have to key in this ids into the backend system. If I ask the Admin to re-register all the devices, then this is a very cumbersome work.

So I think 14 characters length is still lesser to type compared to 36 characters long advertising id.
Unless I have to create another page to send this id to the backend to register the new id. Here I also need to ask the backend developer to build a new webservice or API so it can be called from the B4A app. I don't know this is possible since the backend system is also not maintain and difficult to ask the backend developer to build a new web service.
 
Top