how to add date and time ?
ArrayList<ContentProviderOperation> content_provider_operation=new ArrayList<ContentProviderOperation>();
content_provider_operation.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).withValue(ContactsContract.RawContacts.ACCOUNT_TYPE,null).withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null).build());
//Display Name
if (name1 != null) {
content_provider_operation.add(ContentProviderOperation
.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(
ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(
ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
name1).build());
}
//Mobile Number
if (mobile_number1 != null) {
content_provider_operation.add(ContentProviderOperation
.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(
ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER,
mobile_number1)
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)
.build());
}
if(home_number1!=null)
{
content_provider_operation.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, home_number1)
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE,ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)
.build());
}
// if()
try {
ctc.getContentResolver()
.applyBatch(ContactsContract.AUTHORITY, content_provider_operation);
} catch (Exception e) {
e.printStackTrace();
//show exception in toast
Toast.makeText(ctc, "Exception: " + e.getMessage(),
Toast.LENGTH_SHORT).show();
}
return "contacts inserted";
}
This is the code i have used to add name and number.I want to add date and time in this ? how to do that in content provider in android ?