Android Question How to fetch google contacts into my application

ykucuk

Well-Known Member
Licensed User
Longtime User
Hi developers,

I'm currently working on an application that needs to access a user's Google Contacts. However, I'm not sure how to do this. Can anyone guide me on how to fetch Google Contacts into my application?

Ideally, I would like to be able to authenticate the user with their Google account and then retrieve their contacts using the Google Contacts API. However, I'm not familiar with how to set this up and would appreciate any guidance or resources that you can share.

Thank you in advance for your help!
 

ykucuk

Well-Known Member
Licensed User
Longtime User
I use this class:
As i understand its for local device. I need get contacts from google contacts
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

andredamen

Active Member
Licensed User
Longtime User
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private btnOpnemen As Button
    Private cmbAliassen As B4XComboBox
    Private edtAliasNaam As EditText
    Private lblSpeler As Label
    Private lblTekst As Label
    
    Private cu As ContactsUtils                        '  this is what you need ykucuk
    Dim sf As StringFunctions

    Private btnWegAliasNaam As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    Activity.LoadLayout("AliasNaam")
    Activity.Title = "Contacten koppelen"
    
    sf.Initialize
    cu.Initialize

    Dim Items As List                 '  this is what you need ykucuk
    Items.Initialize                       '  this is what you need ykucuk
    
    lblTekst.Text = "De Whatsapp export zoekt op je telefoon naar bekende telefoonnummers. Wordt zo'n nummer gevonden, dan wordt in het exportbestand niet het 06-nummer weergegeven, maar in plaats daarvan de naam van dit contact. De Tossapp zoekt bij het importeren op 06-nummer en vindt de app dit nummer niet, dan zoekt de app op naam."
    lblTekst.Text = lblTekst.Text & CRLF & "Komt die naam in jouw contacten, en dus in het Whatsapp exportbestand exact overeen met de naam in de database van de Toss app, dan is er niets aan de hand. Dan wordt er gewoon geïmporteerd. Wijkt de naam ook maar één teken af, dan kan de Toss app niets met deze opgave."
    lblTekst.Text = lblTekst.Text & CRLF & CRLF &  "In dit venster kun je de naam van de speler koppelen met de naam in je contacten. De Toss app gebruikt voortaan deze alias en is beter bruikbaar voor jou."
    lblTekst.Text = lblTekst.Text & CRLF & CRLF &  "Deze alias komt in een aparte database te staan op jouw telefoon. Ga je de Toss app database exporteren om te mailen naar een collega, e-mail dan deze aliasnamen.db niet mee! Deze aliassen en dus jouw contacten blijven privé"
    
    lblSpeler.Text = Main.Deelnemernaam
    edtAliasNaam.text = Main.DeelnemersAlias
    
    Dim Dummy As String                                                                '  this is what you need ykucuk
    For Each c As cuContact In cu.FindAllContacts(True)                   '  this is what you need ykucuk                  this gets the names from your phone
        Dummy = c.DisplayName                                                        '  this is what you need ykucuk
        Dummy = sf.Trim(Dummy)                                                       '  this is what you need ykucuk
        Items.Add(Dummy)                                                                   '  this is what you need ykucuk
        'Log(Dummy)
    Next                                                                                                '  this is what you need ykucuk

    cmbAliassen.SetItems(Items)                                                           '  this is what you need ykucuk
End Sub
 
Upvote 0

ykucuk

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private btnOpnemen As Button
    Private cmbAliassen As B4XComboBox
    Private edtAliasNaam As EditText
    Private lblSpeler As Label
    Private lblTekst As Label
  
    Private cu As ContactsUtils                        '  this is what you need ykucuk
    Dim sf As StringFunctions

    Private btnWegAliasNaam As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
  
    Activity.LoadLayout("AliasNaam")
    Activity.Title = "Contacten koppelen"
  
    sf.Initialize
    cu.Initialize

    Dim Items As List                 '  this is what you need ykucuk
    Items.Initialize                       '  this is what you need ykucuk
  
    lblTekst.Text = "De Whatsapp export zoekt op je telefoon naar bekende telefoonnummers. Wordt zo'n nummer gevonden, dan wordt in het exportbestand niet het 06-nummer weergegeven, maar in plaats daarvan de naam van dit contact. De Tossapp zoekt bij het importeren op 06-nummer en vindt de app dit nummer niet, dan zoekt de app op naam."
    lblTekst.Text = lblTekst.Text & CRLF & "Komt die naam in jouw contacten, en dus in het Whatsapp exportbestand exact overeen met de naam in de database van de Toss app, dan is er niets aan de hand. Dan wordt er gewoon geïmporteerd. Wijkt de naam ook maar één teken af, dan kan de Toss app niets met deze opgave."
    lblTekst.Text = lblTekst.Text & CRLF & CRLF &  "In dit venster kun je de naam van de speler koppelen met de naam in je contacten. De Toss app gebruikt voortaan deze alias en is beter bruikbaar voor jou."
    lblTekst.Text = lblTekst.Text & CRLF & CRLF &  "Deze alias komt in een aparte database te staan op jouw telefoon. Ga je de Toss app database exporteren om te mailen naar een collega, e-mail dan deze aliasnamen.db niet mee! Deze aliassen en dus jouw contacten blijven privé"
  
    lblSpeler.Text = Main.Deelnemernaam
    edtAliasNaam.text = Main.DeelnemersAlias
  
    Dim Dummy As String                                                                '  this is what you need ykucuk
    For Each c As cuContact In cu.FindAllContacts(True)                   '  this is what you need ykucuk                  this gets the names from your phone
        Dummy = c.DisplayName                                                        '  this is what you need ykucuk
        Dummy = sf.Trim(Dummy)                                                       '  this is what you need ykucuk
        Items.Add(Dummy)                                                                   '  this is what you need ykucuk
        'Log(Dummy)
    Next                                                                                                '  this is what you need ykucuk

    cmbAliassen.SetItems(Items)                                                           '  this is what you need ykucuk
End Sub
Thank you for the help but exactly I need to get contacts from the cloud (google clouds) not a local phone
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
You need to use the Google Rest API from the B4x HTTP library.

You should authenticate using oAUTH 2

The exact code is dependant upon what contact information you require.
 
Upvote 0
Top