Android Question Getting device phone number in Starter service.

toby

Well-Known Member
Licensed User
Longtime User
My app used to get the phone number in Starter's Service_Create using PhoneId library. After updating android:targetSdkVersion="28" from 19 in the Manifest file, my app needs to check runtime permission, which only works in an activity.

I want to ensure the following sequence:
1. Service_Create
2. Activity_Create
3. Service_Start

I want the device's phone number, if any, be ready before Service_Start is called. The following code is located in Activity_Create:
getting device phone number:
    rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        'we have permission!
        Dim pi As PhoneId
        Starter.strCell  =pi.GetLine1Number

        Log("cell phone number=" & Starter.strCell)
       
    End If

Any suggestion would be greatly appreciated!


TIA
 

Attachments

  • StarterGetCellNumber.zip
    8.6 KB · Views: 156
Last edited:

JohnC

Expert
Licensed User
Longtime User
From what I understand, with the newer versions of android/devices, there is no reliable way to get the phone number anymore - GetLine1Number might return a null string with recent android versions/devices.
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
From what I understand, with the newer versions of android/devices, there is no reliable way to get the phone number anymore - GetLine1Number might return a null string with recent android versions/devices.
I understand that it's not reliable and I just want to save user some typing by suggesting the detected one if one is returned.
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
My Solution:
add to end of Activity_Create:
CallSubDelayed(Starter, "Activity_Create_Complete")

Add to Service_Create:
Wait For Activity_Create_Complete
Log(strCell)
 
Upvote 0
Top