Android Question Get device id without permission

devmobile

Active Member
Licensed User
I need device id but without permission
Because if user uncheck READ_DEVICE_STATE permission,i cannot get it
I need device id only please
 

Johan Schoeman

Expert
Licensed User
Longtime User
Upvote 0

Harris

Expert
Licensed User
Longtime User
B4X:
GetDeviceId As Map
 
    Dim p As Phone
    Dim id As String
    Dim r As Reflector
    Dim Api As Int
    Dim nam, model As String
    Dim mp As Map
    mp.Initialize
    
    Api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")
    nam = p.Manufacturer
    model = p.model
    mp.Put("manu",nam)
    mp.Put("model",model)
    
    Log(" DEVICE Name: "&nam&"   Model: "&model)
    
    If Api < 9 Then
        'Old device
        id = p.GetSettings("android_id")
        Log(" API less than 9")
        mp.Put("serial",id)
        Return mp
    Else
        'New device
        id = r.GetStaticField("android.os.Build", "SERIAL")
 
        If id.ToLowerCase = "unknown" Then
            id = p.GetSettings("android_id")
            Log(" unknown - using phone device id")
        Else
            Log(" API returned a valid serial "& id)
        
        End If
        mp.Put("serial",id)
 
        Return mp
    End If
End Sub
 
Upvote 0

devmobile

Active Member
Licensed User
B4X:
GetDeviceId As Map
 
    Dim p As Phone
    Dim id As String
    Dim r As Reflector
    Dim Api As Int
    Dim nam, model As String
    Dim mp As Map
    mp.Initialize
   
    Api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")
    nam = p.Manufacturer
    model = p.model
    mp.Put("manu",nam)
    mp.Put("model",model)
   
    Log(" DEVICE Name: "&nam&"   Model: "&model)
   
    If Api < 9 Then
        'Old device
        id = p.GetSettings("android_id")
        Log(" API less than 9")
        mp.Put("serial",id)
        Return mp
    Else
        'New device
        id = r.GetStaticField("android.os.Build", "SERIAL")
 
        If id.ToLowerCase = "unknown" Then
            id = p.GetSettings("android_id")
            Log(" unknown - using phone device id")
        Else
            Log(" API returned a valid serial "& id)
       
        End If
        mp.Put("serial",id)
 
        Return mp
    End If
End Sub
Is it OK in any device or android version?
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
If Api < 9 Then
'Old device ' like 2.3 version

Else
'New device - 3.0 and up...
id = r.GetStaticField("android.os.Build", "SERIAL")


Give it a try on old and new devices.... Proof is in the pudding.

Thanks
 
Upvote 0

devmobile

Active Member
Licensed User
Thanks
If Api < 9 Then
'Old device ' like 2.3 version

Else
'New device - 3.0 and up...
id = r.GetStaticField("android.os.Build", "SERIAL")


Give it a try on old and new devices.... Proof is in the pudding.

Thanks

B4X:
GetDeviceId As Map
 
    Dim p As Phone
    Dim id As String
    Dim r As Reflector
    Dim Api As Int
    Dim nam, model As String
    Dim mp As Map
    mp.Initialize
   
    Api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")
    nam = p.Manufacturer
    model = p.model
    mp.Put("manu",nam)
    mp.Put("model",model)
   
    Log(" DEVICE Name: "&nam&"   Model: "&model)
   
    If Api < 9 Then
        'Old device
        id = p.GetSettings("android_id")
        Log(" API less than 9")
        mp.Put("serial",id)
        Return mp
    Else
        'New device
        id = r.GetStaticField("android.os.Build", "SERIAL")
 
        If id.ToLowerCase = "unknown" Then
            id = p.GetSettings("android_id")
            Log(" unknown - using phone device id")
        Else
            Log(" API returned a valid serial "& id)
       
        End If
        mp.Put("serial",id)
 
        Return mp
    End If
End Sub
Hey
I use your code for get id
But it is different of with phoneid
0452256a8291ace3 it is for your code
358240057485864 and is it for phoneid in Phone library
Why they are different?
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Thanks



Hey
I use your code for get id
But it is different of with phoneid
0452256a8291ace3 it is for your code
358240057485864 and is it for phoneid in Phone library
Why they are different?


I see two different numbers but I don't understand where they come from... Your statement above is not very clear to me...
Is one from the actual phone itself (like in the About form from Settings menu)?

Which section did the code retrieve from (old -
id = p.GetSettings("android_id")

or new device method
id = r.GetStaticField("android.os.Build", "SERIAL")

What did the log say?

Anyway, I have noticed that the code fetches the number from the system somewhere - and it may not match what settings reports.
It could be a MAC of wifi chip or something unique. The code will always return the same number for the device it got it from.
 
Upvote 0

devmobile

Active Member
Licensed User
I see two different numbers but I don't understand where they come from... Your statement above is not very clear to me...
Is one from the actual phone itself (like in the About form from Settings menu)?

Which section did the code retrieve from (old -
id = p.GetSettings("android_id")

or new device method
id = r.GetStaticField("android.os.Build", "SERIAL")

What did the log say?

Anyway, I have noticed that the code fetches the number from the system somewhere - and it may not match what settings reports.
It could be a MAC of wifi chip or something unique. The code will always return the same number for the device it got it from.
I use android_id finally
Thanks
 
Upvote 0

devmobile

Active Member
Licensed User
I see two different numbers but I don't understand where they come from... Your statement above is not very clear to me...
Is one from the actual phone itself (like in the About form from Settings menu)?

Which section did the code retrieve from (old -
id = p.GetSettings("android_id")

or new device method
id = r.GetStaticField("android.os.Build", "SERIAL")

What did the log say?

Anyway, I have noticed that the code fetches the number from the system somewhere - and it may not match what settings reports.
It could be a MAC of wifi chip or something unique. The code will always return the same number for the device it got it from.
android_id is working in all device?
I use GetSetting in phone library
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
So i use GetSetting(“android_id”) and your code
Ok?
The code I supplied let's the device decide what to return...
Api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")

I don't know if newer versions of the OS support the older GetSetting(“android_id”)... But hey, if it works for you - fill your boots!
 
Upvote 0
Top