Android Question getting google accounts on android 8 & 9

Discussion in 'Android Questions' started by PassionDEV, Apr 19, 2019.

  1. PassionDEV

    PassionDEV Active Member Licensed User

    i have tried to use this function on android 9 and i couldn't get the google accounts on the device but its return empty on android 9 i have already added permission to the manifest


    Code:
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "5" android:targetSdkVersion="26"/>
    <supports-screens android:largeScreens=
    "true"
        android:normalScreens=
    "true"
        android:smallScreens=
    "true"
        android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetApplicationAttribute(android:
    label"$LABEL$")
    CreateResourceFromFile(Macro, Themes.DarkTheme)
    'End of default text.

    AddPermission(android.permission.GET_ACCOUNTS)

    Code:
    Sub Activity_Create(FirstTime As Boolean)
       
    'Do not forget to load the layout file created with the visual designer. For example:
       Activity.LoadLayout("1")

          
       rup.CheckAndRequest(rup.PERMISSION_GET_ACCOUNTS)
       
    Wait For Activity_PermissionResult(Permission As String, Result As Boolean)
       
    If Result Then
           Gaccount = Result
       
    Else
       
    End If
    Dim Googleaccounts as string


    Googleaccounts = GetGoogleaccounst 

    log("Email : " & Googleaccounts) 'is empty on android 8 and 9

    End Sub


    Sub GetGoogleaccounst As String
        
    Dim r As Reflector
        r.Target = r.RunStaticMethod(
    "android.accounts.AccountManager""get", _
          
    Array As Object(r.GetContext), Array As String("android.content.Context"))
        
    Dim accounts() As Object
        accounts = r.RunMethod2(
    "getAccountsByType","com.google""java.lang.String")
        
    For i = 0 To accounts.Length - 1
            r.Target = accounts(i)
            
    Dim accountName As String
            accountName = r.GetField(
    "name")
            
    Log(accountName)
        
    Next
        
        
    Return accountName
        
        
    End Sub
     
  2. PassionDEV

    PassionDEV Active Member Licensed User

    my bad i needed to add

    Code:
    AddPermission("android.permission.READ_CONTACTS")
    now works fine
     
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