这是android上的一个工程,是从其它地方弄过来的,因为原有的工程有很多 Bug,但是修改起来没慢,也没有申请到权限,我就自己建了一个,我会一直保持这个工程的更新,自己刚好也可以熟悉一下开源的东西怎么玩哈。
地址:http://code.google.com/p/contactlib/
关于工程详细的情况我日后再补。
===================
今日更新:
更新使用方法:
联系人的操作:
- Add new Person
ContactsInterface helper = new ContactsHelper(ctx);
PersonContact testGuy = PersonContact.newPersonContact(null);
PersonName name = PersonName.newPersonName("FirstName", "LastName",
null, null, null);
TelephoneNumber tel = TelephoneNumber.newTelephoneNumber("123123123",
3, null);
TelephoneNumber tel2 = TelephoneNumber.newTelephoneNumber("1231231230",
1, null);
TelephoneNumber tel3 = TelephoneNumber.newTelephoneNumber(
"123123123123", 2, null);
EmailAddress email = EmailAddress.newEmailAddress(
"personcontact@gmail.com", 1, null);
PostalAddress postal = PostalAddress.newPostalAddress(1, null,
"test street", null, null, null, null, "519015", null);
// PostalAddress postal = PostalAddress.newPostalAddress(1, null,
// "test street", "", "", "", "", "519015", "");
Organization org = Organization.newOrganization(1, null, null,
"Kingsoft", "Dev", "Android Dev", "10F-B", "Dev_eng", null);
Organization org1 = Organization.newOrganization(2, null, null, "Home",
null, null, null, "eater", null);
testGuy.name = name;
testGuy.addTelephoneNumber(tel);
testGuy.addTelephoneNumber(tel2);
testGuy.addTelephoneNumber(tel3);
testGuy.addEmailAddress(email);
testGuy.addOrganization(org);
testGuy.addOrganization(org1);
testGuy.addPostalAddress(postal);
try {
helper.add(testGuy);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ContactsInterface helper = new ContactsHelper(ctx);
PersonContact testGuy = PersonContact.newPersonContact(null);
PersonName name = PersonName.newPersonName("FirstName1", "LastName1",
null, null, null);
TelephoneNumber tel = TelephoneNumber.newTelephoneNumber("1123123123",
3, null);
TelephoneNumber tel2 = TelephoneNumber.newTelephoneNumber(
"11231231230", 1, null);
TelephoneNumber tel3 = TelephoneNumber.newTelephoneNumber(
"1123123123123", 2, null);
EmailAddress email = EmailAddress.newEmailAddress(
"personcontact1@gmail.com", 1, null);
PostalAddress postal = PostalAddress.newPostalAddress(1, null,
"1test street", null, null, null, null, "1519015", null);
Organization org = Organization.newOrganization(1, null, null,
"Kingsoft", "Dev", "Android Dev", "10F-B", "Dev_eng", null);
Organization org1 = Organization.newOrganization(2, null, null, "Home",
null, null, null, "eater", null);
testGuy.name = name;
testGuy.addTelephoneNumber(tel);
testGuy.addTelephoneNumber(tel2);
testGuy.addTelephoneNumber(tel3);
testGuy.addEmailAddress(email);
testGuy.addPostalAddress(postal);
testGuy.addOrganization(org);
testGuy.addOrganization(org1);
try {
helper.add(testGuy);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PersonContact pc = helper.getPersonContactById(testGuy.id);
try {
helper.delete(pc);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ContactsInterface helper = new ContactsHelper(ctx);
Iterator<PersonContact> pcs = helper.listContacts();
while (pcs.hasNext()) {
PersonContact p = pcs.next();
try {
helper.delete(p);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
- Delete telphone in a Person
PersonContact pc = helper.getPersonContactById(testGuy.id);
pc.fill(ctx);
Iterator it = pc.telephoneNumbers.iterator();
while (it.hasNext()) {
TelephoneNumber _tel = (TelephoneNumber) it.next();
try {
helper.delete(_tel);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
PersonContact pc = helper.getPersonContactById(testGuy.id);
pc.fill(ctx);
pc.telephoneNumbers.get(0).number = "33333333";
try {
helper.update(pc);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
其它的操作都类似,详细可查看代码。