android---applybatch
l_serein發表於2012-08-11
-
public void insert() {
-
final ContentResolver resolver = getContentResolver();
-
final ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
-
ContentProviderOperation.Builder builder = ContentProviderOperation
-
.newInsert(RawContacts.CONTENT_URI);
-
ContentValues values = new ContentValues();
-
builder.withValues(values);
-
operationList.add(builder.build());
-
builder = ContentProviderOperation
-
.newInsert(android.provider.ContactsContract.Data.CONTENT_URI);
-
builder.withValueBackReference(StructuredName.RAW_CONTACT_ID, 0);
-
builder.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
-
builder.withValue(StructuredName.DISPLAY_NAME, "MP");
-
operationList.add(builder.build());
-
builder = ContentProviderOperation
-
.newInsert(android.provider.ContactsContract.Data.CONTENT_URI);
-
builder.withValueBackReference(Email.RAW_CONTACT_ID, 0);
-
builder.withValue(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
-
builder.withValue(Email.TYPE, Email.TYPE_MOBILE);
-
builder.withValue(Email.DATA, "mp870601@163.com");
-
operationList.add(builder.build());
-
try {
-
resolver.applyBatch(ContactsContract.AUTHORITY, operationList);
-
} catch (RemoteException e) {
-
-
e.printStackTrace();
-
} catch (OperationApplicationException e) {
-
e.printStackTrace();
-
}
-
}