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
Top