Sub Button1_Click
'Add libs phone and my miscUtil
Dim mu As miscUtil, c As Contact
mu.Initialize
Dim name As String, phoneNr As String, phoneType As Int, mail As String, mailType As Int
'define contact data
name = "Mike Tester"
phoneNr = "004912345678"
phoneType = c.PHONE_HOME
mail = "mike@tester.com"
mailType = c.EMAIL_HOME
'create contact
mu.createContactEntry(name, phoneNr, phoneType, mail, mailType)
'thats all folks :-)
'check success, new contact should be the last entry in the list l
Dim cs As Contacts
Dim l As List
l = cs.GetAll
For i = 0 To l.Size - 1
c = l.Get(i)
Log(c)
Next
End Sub
'Add libs phone and my miscUtil
Dim mu As miscUtil, c As Contact
mu.Initialize
Dim name As String
'define contact data
name = "Kuno Maier"
Dim phones As Map, mails As Map
phones.Initialize
phones.Put(c.PHONE_HOME, "1234567890")
phones.Put(c.PHONE_WORK, "0987654321")
mails.Initialize
mails.Put(c.EMAIL_HOME, "mike@tester.com")
mails.Put(c.EMAIL_WORK, "mike@testeroffice.com")
'create contact
mu.createContactEntry2(name, phones, mails)
The zip file doesn't seem to contain a new version of the library only 1.0 , so your new example does not work
One suggestion the name of the library implies that it does many different functions, maybe call it something more descriptive.
Oh sorry for that, v1.04 is attached now.
But it has even improved. You can read and write the photo of the Contact.
Enjoy
phones.Initialize
phones.Put(c.PHONE_HOME, number_entry_home.Text)
phones.Put(c.PHONE_WORK, number_entry_work.Text)
mails.Initialize
mails.Put(c.EMAIL_HOME, email_entry.Text)
mails.Put(c.EMAIL_WORK, email_entry.Text) ' save same email for both entries
' create the new contact
name = name_entry.Text
mu.createContactEntry2(name, Null, phones, mails, "", "", "", Null, Null)
B4X:mu.createContactEntry2(name, Null, phones, mails, "", "", "", Null, Null)
where I pass Null for the values of the photo, and the home and work addresses , but when the compiled app runs I am told that the map must first be initialised.
Dim adressehome As Map
adressehome.Initialize
adressehome.Put(0, "") 'town
adressehome.Put(1, "") 'zip
adressehome.Put(2, "") 'street
adressehome.Put(3, "") 'country
Dim adressework As Map
adressework.Initialize
adressework.Put(0, "") 'town
adressework.Put(1, "") 'zip
adressework.Put(2, "") 'street
adressework.Put(3, "") 'country
mu.createContactEntry2(name, Null, phones, mails, "", "", "", adressehome, adressework)
public Boolean DeleteAllConcacts(){
ContentResolver cr = this.m_ba.context.getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
while (cur.moveToNext()) {
try{
String lookupKey = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
cr.delete(uri, null, null);
}
catch(Exception e)
{
return false;
}
}
return true;
}
I wonder if there is going to be an option to create a GROUP in contacts.
Sub CreateGropTest
Dim MyGroups As Map
Dim j As Int
Dim mu As miscUtil
mu.Initialize
'lets explore the current available groups
MyGroups = mu.GetGroupMap
For j=0 To MyGroups.Size - 1
Log("Group " & MyGroups.GetKeyAt(j) & " - " & MyGroups.GetValueAt(j) )
Next
'create the new group
mu.createGroupEntry("MyNewGroup")
'lets explore the current available groups again
'map shold contain the new group now
MyGroups = mu.GetGroupMap
For j=0 To MyGroups.Size - 1
Log("Group " & MyGroups.GetKeyAt(j) & " - " & MyGroups.GetValueAt(j) )
Next
End Sub
:sign0098:Here is something for your lib.
Delete all contacts.
Get the Version 1.06 or higher and use createGroupEntry("MyNewGroup")
Example:
B4X:Sub CreateGropTest Dim MyGroups As Map Dim j As Int Dim mu As miscUtil mu.Initialize 'lets explore the current available groups MyGroups = mu.GetGroupMap For j=0 To MyGroups.Size - 1 Log("Group " & MyGroups.GetKeyAt(j) & " - " & MyGroups.GetValueAt(j) ) Next 'create the new group mu.createGroupEntry("MyNewGroup") 'lets explore the current available groups again 'map shold contain the new group now MyGroups = mu.GetGroupMap For j=0 To MyGroups.Size - 1 Log("Group " & MyGroups.GetKeyAt(j) & " - " & MyGroups.GetValueAt(j) ) Next End Sub
:sign0098:
I would never, never call this function in real live, because i collected my contacts over a log time.
Attached new version v1.06 contains your contribution. Thank you.
Will you add more features like ...Attached new version v1.06 contains your contribution. Thank you.
Hi
I need to add several (hundred) numbers to one contact. Is that possible with miscUtil?
/Ronny
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?