Android Question How to put all contacts in one textbox and compile them in a .txt file

alvin1929

Member
I already have the contentresolver library and already tried samples in the forum. Here's the code:

B4X:
Sub Process_Globals
    Private cu As ContactsUtils
    Private rp As RuntimePermissions
End Sub

Sub Globals
    Private ImageView1 As B4XView
    Private EditText1 As B4XView
    Private CLV1 As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        cu.Initialize
    End If
    Activity.LoadLayout("1")
    rp.CheckAndRequest(rp.PERMISSION_WRITE_CONTACTS)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        For Each c As cuContact In cu.FindAllContacts(True)
            CLV1.AddTextItem(c.DisplayName, c)
        Next
    Else
        ToastMessageShow("No permission", True)
    End If
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub CLV1_ItemLongClick (Index As Int, Value As Object)
    Dim c As cuContact = Value
    cu.SetStarred(c.Id, Not(cu.GetStarred(c.Id)))
    'update the text
    CLV1_ItemClick(Index, Value)
End Sub

Sub CLV1_ItemClick (Index As Int, Value As Object)
    Dim c As cuContact = Value
    Dim bmp As Bitmap = cu.GetPhoto(c.Id)
    If bmp.IsInitialized Then ImageView1.SetBitmap(bmp) Else ImageView1.SetBitmap(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

Is it possible to compile all contacts in a .txt file?
 
Top