Android Question Owner accounts with all field

brelto85

Active Member
Licensed User
Longtime User
The first method return a owner account with some fields but there isn't a email
The second method list the accounts owner returns only a emails value

B4X:
Sub GetOwnerAccount() As Cursor
      Dim cr As ContentResolver
      Dim u As Uri
      u.Parse("content://com.android.contacts/profile")
      cr.Initialize("cr")
      Dim crsr As Cursor = cr.Query(u, Null, "", Null, "")
      crsr.Position = 0
      Return crsr
End Sub

Public Sub GetAccounts As List
    Dim r As Reflector
    Dim wAccounts As List
    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
    accounts = r.RunMethod2("getAccountsByType", "com.google", "java.lang.String")
    For i = 0 To accounts.Length - 1
          r.Target = accounts(i)
        wAccounts.Add(r.GetField ("name"))
      Next
    Return wAccounts
End Sub

How to merge?
I need to list the owner accounts recovering the email, name, surname and picture for each profile
 

JOTHA

Well-Known Member
Licensed User
Longtime User
This code will print the account name (as well as the other fields).

Hi Erel,
at the first time I had this code:
B4X:
  For r = 0 To c.RowCount - 1
    c.Position = r
    For col = 0 To c.ColumnCount - 1
      Log(c.GetColumnName(col) & ": " & c.GetString2(col))
    Next
  Next

The result was this Log:
times_contacted: 0


index_in_sim: -1
phonetic_name: null
data_set: null


phonetic_name_style: 3
contact_id: 9223372034707292161
version: 7
send_to_voicemail_sip: 0
timestamp: null
last_time_contacted: null
aggregation_mode: 0
_id: 9223372034707292161
name_verified: 0
dirty: 1
display_name_source: 40
send_to_voicemail: 0
account_type: null
account_type_and_data_set: null
send_to_voicemail_vt: 0
custom_ringtone: null
sync4: null
sync3: null
sync2: null
sync1: null
deleted: 0
account_name: null
display_name: John Doe
raw_contact_is_user_profile: 1
sort_key_alt: Doe, John
indicate_phone_or_sim_contact: -1
starred: 0
sort_key: John Doe
display_name_alt: Doe, John
sourceid: null
is_sdn_contact: 0
***************

... then I took this (new) code above:
B4X:
  For r = 0 To c.RowCount - 1
    c.Position = r
    For col = 0 To c.ColumnCount - 1
   
      Try
        Log(c.GetColumnName(col) & ": " & c.GetString2(col))

      Catch
        Log(c.GetColumnName(col) & ": " & LastException)
       
      End Try
     
    Next
    Log("***************")
  Next

I got the same result at using both codes, but there was no E-Mail and no SIM-Number. :(
The only Value I got was the Name.

So how can I get the E-Mail and the SIM-Number?
 
Upvote 0

Croïd

Active Member
Licensed User
Longtime User
This is correct. You need to change Array(...) to Array As Object(...) if you are using an older version of B4A.

The security error is the error I was talking about.


Please, what parameter t I miss him?
 

Attachments

  • zzz.zip
    492.7 KB · Views: 446
Last edited:
Upvote 0

Croïd

Active Member
Licensed User
Longtime User
I Have problème with : To Array As Object(GetContext))

am = am.InitializeStatic("android.accounts.AccountManager").RunMethod("get", To Array As Object(GetContext))

If I leave Array alone : Error occured : java.lang.reflect.invocationTargetException
 
Upvote 0

Croïd

Active Member
Licensed User
Longtime User
I have no problem with the emulator is to open application on the phone !

With : am = am.InitializeStatic("android.accounts.AccountManager").RunMethod("get", Array(GetContext)) = OK Emulator / No Phone

But what is missing ?

am = am.InitializeStatic("android.accounts.AccountManager").RunMethod("get", To Array As Object(GetContext)) = Impossible BUILD
 
Upvote 0
Top