Android Question java.lang.SecurityException: getDeviceId:

Discussion in 'Android Questions' started by cambol, Aug 5, 2018.

  1. cambol

    cambol 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.
     
  2. Mahares

    Mahares Well Known Member Licensed User

    You need something like this:
    Code:
    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
     
    DonManfred and Erel like this.
  3. cambol

    cambol Member Licensed User

    thanks ~ it work !
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice