android---applybatch

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, "[email protected]");
  operationList.add(builder.build());
  try {
   resolver.applyBatch(ContactsContract.AUTHORITY, operationList);
  } catch (RemoteException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (OperationApplicationException e) {
   e.printStackTrace();
  }
}


你可能感兴趣的:(android,mobile)