Android Question java.lang.SecurityException: getDeviceId:

cambol

Active Member
Licensed User
Error in targetSdkVersion 23+

java.lang.SecurityException: getDeviceId: Neither user 10223 nor current process has android.permission.READ_PHONE_STATE.




code :

Sub Process_Globals
.....
Dim id1 As String
Dim rp As RuntimePermissions

End Sub



Sub Activity_Create(FirstTime As Boolean)
...
rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
id1 = pid.GetDeviceId




AddManifestText(
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddPermission(android.permission.READ_PHONE_STATE)
'End of default text.
 

Mahares

Expert
Licensed User
Longtime User
java.lang.SecurityException: getDeviceId: Neither user 10223 nor current process has android.permission.READ_PHONE_STATE
You need something like this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)  '
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        MsgboxAsync("No permission to access phone id", "")
        Return
    Else
        Dim id1 As String
        Dim pid As PhoneId
        id1 = pid.GetDeviceId
        Log(id1)
    End If
End Sub
 
Upvote 0
Top