TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Nandhini Jayachandran
NA
117
43.1k
how to add date and time ?
Sep 13 2014 11:36 AM
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 ?
Reply
Answers (
1
)
How to ristrict only one application installation in android
Error while inserting date and time in sqlite database