Android Question SDK33 - how to get unique number of phone

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

please for advice,
I think this question is not first here, but I can not find similar question,
please for advice how to get unique number of smartphone if I am using sdk 33 with B4A?

Best regards
p4ppc
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
Please very much for advice,

in Activity_create is code:
B4X:
     Dim rp5 As RuntimePermissions
    rp5.CheckAndRequest(rp5.PERMISSION_READ_PHONE_STATE)
    wait for Activity_PermissionResult(permission As String, result As Boolean) 
     If result=True Then  
                 Log("ReadPHst")                                     
                 Dim ph As PhoneId
                 Log(ph.GetDeviceId)
                 Log(ph.GetSubscriberId) 
      Else

    End If

in Manifest is:
B4X:
 AddPermission(android.permission.READ_PHONE_STATE)

ReadPHst
main$ResumableSub_Activity_Createresume (java line: 1646)
java.lang.SecurityException: getDeviceId: The user 10628 does not meet the requirements to access device identifiers.
at android.os.Parcel.createExceptionOrNull(Parcel.java:2438)
at android.os.Parcel.createException(Parcel.java:2422)
at android.os.Parcel.readException(Parcel.java:2405)
at android.os.Parcel.readException(Parcel.java:2347)
at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceIdWithFeature(ITelephony.java:12085)
at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:2514)
at anywheresoftware.b4a.phone.Phone$PhoneId.GetDeviceId(Phone.java:479)
at goxc125.ap.mobile.main$ResumableSub_Activity_Create.resume(main.java:1646)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
ST:java.lang.SecurityException: getDeviceId: The user 10628 does not meet the requirements to access device identifiers.
at android.os.Parcel.createExceptionOrNull(Parcel.java:2438)
at android.os.Parcel.createException(Parcel.java:2422)
at android.os.Parcel.readException(Parcel.java:2405)
at android.os.Parcel.readException(Parcel.java:2347)
at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceIdWithFeature(ITelephony.java:12085)
at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:2514)
at anywheresoftware.b4a.phone.Phone$PhoneId.GetDeviceId(Phone.java:479)
at goxc125.ap.mobile.main$ResumableSub_Activity_Create.resume(main.java:1646)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

but app crashed after "ReadPHst". I think I am doing something wrong with permission.
Please very much for advice,
p4ppc
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
My mistake. I remembered that it is no longer possible to access the phone number but didn't find the restriction when I searched.

The answer is here:

It is not possible to get the phone number in Android 10+ (might be possible for non-Google Play apps).
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Thank you very much, I understand,

for certain I must ask:
I dont need phone number, but I need some unique id of phone device,
is here some possibility (for example as was advertising id?
(advertising id is not possible to use now because I get only zeros: 00000000000000)

Best regards
p4ppc
 
Last edited:
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Advertising id should work if Google Play is available. There is no other unique id.
Google play is available and advertising id (with SDK 33) is not OK, I get: 000000000000000000000
B4X:
Wait For (GetAdvertisingId) Complete (Id As String)

with SDK 30 is the number OK.

Best regards
p4ppc
 
Upvote 0

Rubsanpe

Active Member
Licensed User
Hi. If I remember correctly, in your AdMob account you must indicate that you want to access the device's advertising identifier. It is one of the questions you are asked to comply with AdMob rules. If you don't specify it the code returned is all 0. I think it is required from SDK 31.

Rubén
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Please, put SOLVED in the thread title when you solved a question, so other peoples can see it.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Google play is available and advertising id (with SDK 33) is not OK, I get: 000000000000000000000
B4X:
Wait For (GetAdvertisingId) Complete (Id As String)

with SDK 30 is the number OK.

Best regards
p4ppc
if i may,
i also was struggling with that topic and found, i think, a better solution
advertising id is "problematic" as not all have google play
some do block this id
and it requires you to work with it

my solution is much simpler and works for me:
on first run create a file with an GUID or just take the device id as shown in the following code sample

then on each run check if the file exists and read it
if you use device id not GUID no need for file

now you have an id to work with
this id will change every time you install fresh but stay on updates
i chose the GUID as it provides me more features
you can combine them...

this is used in my registration and licensing engine for quite a long time now
i use a OEM like license so if the user changes the device or remove and reinstall it is my choice to grant free or charge
the main thing is that i can identify the user and device

B4X:
    Dim DEviceID As String=""
    Dim p As Phone
        
    Try
                
        DEviceID = P.GetSettings("android_id").ToUpperCase
             
        Log($"DeviceID: ${DEviceID}"$)
    
    Catch
        
        Log(LastException)
        DEviceID = ""
        
    End Try
    
    Log(DEviceID)
    Return DeviceID


hope i did some help here
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
please for advice,
I think this question is not first here, but I can not find similar question,
please for advice how to get unique number of smartphone if I am using sdk 33 with B4A?
In short, it means that Google is imposing more and more restrictions on a unique ID for privacy reasons. The fewer restrictions, the greater the chance that the ID will be used to track user activity.

Instead of following all kinds of elephant paths that are closed at the next API level after discovery by Google, why not create a unique user ID in the program memory that only your own program has access to? Then it is API independent, no other program has access to it (privacy guaranteed), the ID remains unaffected during a program update, and the ID remains usable until the program is uninstalled.
 
Upvote 0
Top