Android Question How can I get phone mumber from ContactsUtils

Beja

Expert
Licensed User
Longtime User
Hello,
Something weird.. I used the code below to get all phone contacts in a list.. instead I get the contacts of my Skype (not the phone).
Any help appreciated.

B4X:
Sub lstContacts_ItemClick (Position As Int, Value As Object)
	Dim c As cuContact = Value
	Dim bmp As Bitmap = cu.GetPhoto(c.Id)
	If bmp.IsInitialized Then ImageView1.SetBackgroundImage(bmp) Else ImageView1.SetBackgroundImage(Null)
	Dim sb As StringBuilder
	sb.Initialize
	'sb.Append(c.DisplayName).Append(CRLF).Append("Note: ").Append(cu.GetNote(c.Id)).Append(CRLF)
	'sb.Append("Starred: ").Append(cu.GetStarred(c.Id)).Append(CRLF)
	
	For Each phone As cuPhone In cu.GetPhones(c.Id)
		sb.Append(phone.Number & ", " & phone.PhoneType).Append(CRLF)
	Next
	For Each email As cuEmail In cu.GetEmails(c.Id)
		sb.Append(email.email).Append(", ").Append(email.EmailType).Append(CRLF)
	Next
	EditText1.Text = sb.ToString
End Sub

Sub lstContacts_ItemLongClick (Position As Int, Value As Object)
	'toggle the starred state
	Dim c As cuContact = Value
	cu.SetStarred(c.Id, Not(cu.GetStarred(c.Id)))
	'update the text
	lstContacts_ItemClick(Position, Value)
End Su
 

Beja

Expert
Licensed User
Longtime User
I uninstalled Skype with all its contacts.. now the example app doesn't show my phone contacts..
Any help please.. this is a disaster for me.

edit:
I am using Alcatel onetouch - 7040N, and Android 4.4.2
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hi Erel,

I assume it is this one:
B4X:
    For Each phone As cuPhone In cu.GetPhones(c.Id)
        sb.Append(phone.Number & ", " & phone.PhoneType).Append(CRLF)
    Next
[code]

(extracted from the code above)
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
This any help to you?

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim details, cName, cphone As String
    Dim listOfContacts As List
    Dim lvphone As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
    getcontacts
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub getcontacts
    Dim Contacts2 As Contacts2
    listOfContacts.Initialize
    listOfContacts = Contacts2.GetAll(True,False)
    'Log(listOfContacts)
   
      'listOfContacts.Sort(True)
    'Log(listOfContacts)
       
    For i = 0 To listOfContacts.Size - 1
        Dim Contact As Contact
        Contact = listOfContacts.Get(i)
        'Log(Contact) 'will print the fields to the LogCat
 
        If Contact.PhoneNumber <>"" Then 
            'If there Is a Contact number pass it To the ListView so you can see it
                                
            'lvphone.TwoLinesLayout.SecondLabel.textcolor=Colors.blue
            lvphone.SingleLineLayout.Label.TextSize = 20
            lvphone.SingleLineLayout.ItemHeight = 70
            lvphone.AddSingleLine(Contact.DisplayName &CRLF &Contact.PhoneNumber)
            'lvphone.AddTwoLines(Contact.DisplayName,Contact.PhoneNumber)
            lvphone.ScrollingBackgroundColor =Colors.DarkGray
         End If
    Next  

End Sub

Sub lvphone_ItemClick (Position As Int, Value As Object)  As String
    
     details = Value
     'Log("******************************************")
     'Log("selected " & details)  'the name in the logs As a check
   
    'Log("Break found at " & details.IndexOf(CRLF))
    'Log("******************************************")
    cName=details.SubString2(0,details.IndexOf(CRLF))
   
   
    Log("Name selected -" & cName & "-")
    cphone=details.SubString2(details.IndexOf(CRLF)+1,details.Length)
   
   
    Log("Phone number -" & cphone & "-")
    Activity.Title=cName & "-" & cphone
    Return details
   
End Sub

Is old code but should still work.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hi Erel
it is the same as contactsutils sample
 

Attachments

  • ContactsUtils.zip
    10.5 KB · Views: 233
Last edited:
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Yes, this is true. What about using SQL? I have been using this for years with Skype installed, no problem.
 

Attachments

  • FavContacts.zip
    2 KB · Views: 206
Upvote 0

Beja

Expert
Licensed User
Longtime User
Yep!
Thank you Erel.. Now it works like a charm. All the contact info is out.. (phone numbers, emails, etc)

@mark,
Thanks and I would try the SQL method, but I didn't know how to design the "main.bal" and it's missing.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Sorry, the code in post #6 is not runable as it is only part of the app. My code in post #8 is also only partial. Here is the complete code for the SQL example if you wish.
 

Attachments

  • App.zip
    29.5 KB · Views: 228
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hello Mark,
Your project is perfect and very professional.. thanks for sharing..
Notice: navigation information is important.. either by help file or use of menus, tags or buttons. Now (I think) it depends on
common sense of experienced users. for example, when clicking on Setup, and the setup window comes up, then it would be
very helpful to drop a line of text explaining what to do next.. for example:
Click an item to show more options.. then when clicking an item and go there, another line saying, click on the name to send email, or on the
number to send SMS..
I mean something like this for all the steps will be very helpful for users.
Thanks again for the great work and generous sharing.
 
Upvote 0
Top