Android Question Check if a contact has been added

D

Deleted member 103

Guest
Hi,

Using this code, you can add a contact.
B4X:
    Dim i As Intent
    i.Initialize("android.intent.action.INSERT", "content://com.android.contacts/contacts")
    StartActivity(i)
How to check if a contact was added?
 
D

Deleted member 103

Guest
In fact, it is not the best solution, but if there is no other solution ...

What is the function "StartActivityForResult", so what can you do?
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
How to check if a contact was added?
I would say you can do that easily and effectively using ContentObserver (it will immediately detects the change/add), but unfortunately we do not have it implemented yet in B4A...
However I may be wrong (never tried so before)...
 
Last edited:
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
In fact, it is not the best solution, but if there is no other solution ...
Or... you can use ContentResolver to check if this contact exists there... ContentResolver can be used in B4A.
B4X:
Sub FindContact(phonenumber As String) As String

    Dim phonesUri As Uri, name As String = ""
    phonesUri.Parse("content://com.android.contacts/phone_lookup")
    phonesUri.WithAppendedPath(phonesUri, phonenumber)
    Dim phones As Cursor = cr.Query(phonesUri, Array As String("number", "display_name"),"number = ?", Array As String(phonenumber), "")
    If phones.RowCount > 0 Then
        phones.Position = 0
        name = phones.GetString("display_name")
    End If
    phones.Close
    Return name

End Sub
 
Last edited:
Upvote 0
Top