Hello,
I made a small program to try and get the Google email addresses logged into the device. I tried this code below:
But when I call it with Log(GetEmailList) it always returns me an empty list. I checked and made sure I have the Google account added to the device. In the Manifest I also added the permission:
AddPermission(android.permission.GET_ACCOUNTS)
And it still gives me an empty list. I am running this on Android 9.
I made a small program to try and get the Google email addresses logged into the device. I tried this code below:
B4X:
Public Sub GetEMailList As List
Dim r As Reflector
Dim wAccounts As Map
Dim EMails As List
EMails.Initialize
wAccounts.Initialize
r.Target = r.RunStaticMethod("android.accounts.AccountManager", "get", Array As Object(r.GetContext), Array As String("android.content.Context"))
Dim accounts() As Object
Dim SignIn As String
accounts = r.RunMethod("getAccounts")
For i = 0 To accounts.Length - 1
r.Target = accounts(i)
SignIn = r.GetField("type")
Log("Account:" &i &" " &accounts(i) &" SignIn:" &SignIn)
wAccounts.Put(r.GetField("name"), "")
Next
For Each account As String In wAccounts.Keys
'#if Debug
Log(account)
'#end if
If account.Length > 0 Then
EMails.Add(account)
End If
Next
Return EMails
End Sub
But when I call it with Log(GetEmailList) it always returns me an empty list. I checked and made sure I have the Google account added to the device. In the Manifest I also added the permission:
AddPermission(android.permission.GET_ACCOUNTS)
And it still gives me an empty list. I am running this on Android 9.