public long createRawContact() {
    ensureCallingPackage();
    final ContentValues values = new ContentValues();

    Uri rawContactUri = resolver.insert(RawContacts.CONTENT_URI, values);
    return ContentUris.parseId(rawContactUri);
  }
 public void setSuperPrimaryPhone(long dataId) {
   ensureCallingPackage();
   final ContentValues values = new ContentValues();
   values.put(Data.IS_PRIMARY, 1);
   values.put(Data.IS_SUPER_PRIMARY, 1);
   Uri updateUri = ContentUris.withAppendedId(Data.CONTENT_URI, dataId);
   resolver.update(updateUri, values, null, null);
 }
 public ContentProvider addProvider(
     Class<? extends ContentProvider> providerClass, String authority) throws Exception {
   ContentProvider provider = providerClass.newInstance();
   ProviderInfo info = new ProviderInfo();
   info.authority = authority;
   provider.attachInfo(mProviderContext, info);
   resolver.addProvider(authority, provider);
   return provider;
 }
 public long getContactForRawContact(long rawContactId) {
   ensureCallingPackage();
   Uri contactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
   final Cursor cursor =
       resolver.query(contactUri, Projections.PROJ_RAW_CONTACTS, null, null, null);
   if (!cursor.moveToFirst()) {
     cursor.close();
     throw new RuntimeException("Contact didn't have an aggregate");
   }
   final long aggId = cursor.getLong(Projections.COL_CONTACTS_ID);
   cursor.close();
   return aggId;
 }
 //    public long createRawContactWithStatus(String name, String address,
 //            String status) {
 //        final long rawContactId = createRawContact(name);
 //        final long dataId = createEmail(rawContactId, address);
 //        createStatus(dataId, status);
 //        return rawContactId;
 //    }
 //
 public long createName(long contactId, String name) {
   ensureCallingPackage();
   final ContentValues values = new ContentValues();
   values.put(Data.RAW_CONTACT_ID, contactId);
   values.put(Data.IS_PRIMARY, 1);
   values.put(Data.IS_SUPER_PRIMARY, 1);
   values.put(Data.MIMETYPE, CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
   values.put(CommonDataKinds.StructuredName.FAMILY_NAME, name);
   Uri insertUri =
       Uri.withAppendedPath(
           ContentUris.withAppendedId(RawContacts.CONTENT_URI, contactId),
           RawContacts.Data.CONTENT_DIRECTORY);
   Uri dataUri = resolver.insert(insertUri, values);
   return ContentUris.parseId(dataUri);
 }
 public long createEmail(long contactId, String address) {
   ensureCallingPackage();
   final ContentValues values = new ContentValues();
   values.put(Data.RAW_CONTACT_ID, contactId);
   values.put(Data.IS_PRIMARY, 1);
   values.put(Data.IS_SUPER_PRIMARY, 1);
   values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
   values.put(Email.TYPE, Email.TYPE_HOME);
   values.put(Email.DATA, address);
   Uri insertUri =
       Uri.withAppendedPath(
           ContentUris.withAppendedId(RawContacts.CONTENT_URI, contactId),
           RawContacts.Data.CONTENT_DIRECTORY);
   Uri dataUri = resolver.insert(insertUri, values);
   return ContentUris.parseId(dataUri);
 }
Esempio n. 7
0
 static GalleryAppStub newGalleryContext(SQLiteDatabase db, Looper mainLooper) {
   MockContentResolver cr = new MockContentResolver();
   ContentProvider cp = new DbContentProvider(db, cr);
   cr.addProvider("media", cp);
   return new GalleryAppMock(null, cr, mainLooper);
 }
 public void addAuthority(String authority) {
   resolver.addProvider(authority, mprovider);
 }