B4J Question Reflection library: Unknown member getcontext

toby

Well-Known Member
Licensed User
Longtime User
I've used the code below in B4A to get a list of signed-in Google account Gmail address. Right now I'm porting the code to B4J and got the error in question.

Could someone please tell me how to fix it or how to get the device's signed-in Gmail address by any mean?

TIA


B4A code:
'USAGE: return a list of gmail addresses
'Depends on reflection library
Sub GetGmailAccounts As B4XOrderedMap
    Dim r As Reflector 'reflection lib
    Dim bom As B4XOrderedMap
    bom.Initialize
    
    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, accountType As String
        accountName = r.GetField("name")
        accountType = r.GetField("type")
        bom.Put(accountName, accountType)
        Log("gmail=" &accountName )
        Log("account type=" & accountType)
    Next
    Return bom
End Sub
 
Top