ContentProvider insert - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for ContentProvider insert method.

This code example shows how to use the following methods:insert, query
    	 
    	ContentProvider provider = getProvider();
    	 
    	Uri uri = EventStreamContentProvider.content_uri;
 
    	Cursor c = provider.query(uri, null, null, null, null);    	
    	int entries = c.getCount();
    	c.close();
    	 
    	Uri entryUri = provider.insert(uri, null);
    	c = provider.query(uri, null, null, null, null);
    	assertEquals(entries+1, c.getCount());    
    	 
    	ContentValues values = new ContentValues();    	
		values.put(EventStreamContentProvider.Columns.TEXT, TEST_TEXT);
		long now = System.currentTimeMillis(); 
    	entryUri = provider.insert(uri, values);
    	 
    	assertNotNull(entryUri);
    	 

6
CodeRank
This code example shows how to use the following methods:insert
                childId = ContentUris.parseId(newItem);
 
                // no existing child or relation 
            } else { 
                if (mToContentUri != null) {
                    newItem = provider.insert(mToContentUri, values);
                    childId = ContentUris.parseId(newItem);
                } else { 
                    if (mTo != null) {
                        newItem = mTo.insertDir(db, provider, parentChildDir, values);
                        childId = ContentUris.parseId(newItem);
                    } else { 
                        childId = db.insert(mToTable, null, values);
                        if (childId != -1) {
                            newItem = ContentUris.withAppendedId(parentChildDir, childId);
                        } 
                    } 
                } 
            } 
 
5
CodeRank
This code example shows how to use the following methods:insert
	} 
 
	@Override 
	public Uri insert(Uri uri, ContentValues values) {
		try { 
			return mProvider.insert(uri, values);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} 
		return uri;
	} 
 
	@Override 
	public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
		try { 
			return mProvider.query(uri, projection, selection, selectionArgs, sortOrder);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
5
CodeRank
This code example shows how to use the following methods:insert
		return value.toContentValues();
	} 
 
	static Uri insertValidValue(final int valueId, final ContentProvider provider) {
 
		PersonsTableTest.insertValidValue(PERSON_ID, provider);
		PointsTableTest.insertValidValue(POINT_ID, provider);
		return provider.insert(tableUri, getTestValue(valueId));
	} 
 
	static Uri insertValidValue(final int valueId, final Integer personId, final Integer pointId,
			final ContentProvider provider) {
 
		PersonsTableTest.insertValidValue(personId, provider);
		PointsTableTest.insertValidValue(pointId, provider);
		return provider.insert(tableUri, getTestValue(valueId, personId, pointId));
	} 
 
	private static ContentValues getTestValue(final int id) {
 
5
CodeRank
This code example shows how to use the following methods:insert
	} 
 
	static Uri insertValidValue(final int valueId, final int discussionId, final int pointId,
			final ContentProvider provider) {
 
		DiscussionsTableTest.insertValidValue(discussionId, provider);
		PointsTableTest.insertValidValue(pointId, provider);
		return provider.insert(tableUri, getTestValue(valueId, discussionId, pointId));
	} 
 
	private static ContentValues getTestValue(final int id) {
 
		return getTestValue(id, DISCUSSION_ID, POINT_ID);
	} 
 
	public void testDeleteFromDiscussion() { 
 
		// insert valid value 
		insertValidValue(RANDOM_DESCRIPTION_ID);
		// delete associated table 
5
CodeRank
This code example shows how to use the following methods:insert
                Account account, byte[] data) throws RemoteException {
            ContentValues values = new ContentValues();
            values.put(Columns.DATA, data);
            values.put(Columns.ACCOUNT_NAME, account.name);
            values.put(Columns.ACCOUNT_TYPE, account.type);
            provider.insert(uri, values);
        } 
 
        public static Uri insert(ContentProviderClient provider, Uri uri,
                Account account, byte[] data) throws RemoteException {
            ContentValues values = new ContentValues();
            values.put(Columns.DATA, data);
            values.put(Columns.ACCOUNT_NAME, account.name);
            values.put(Columns.ACCOUNT_TYPE, account.type);
            return provider.insert(uri, values);
        } 
 
        public static void update(ContentProviderClient provider, Uri uri, byte[] data)
                throws RemoteException { 
            ContentValues values = new ContentValues();
4
CodeRank
This code example shows how to use the following methods:insert
                Account account, byte[] data) throws RemoteException {
            ContentValues values = new ContentValues();
            values.put(Columns.DATA, data);
            values.put(Columns.ACCOUNT_NAME, account.name);
            values.put(Columns.ACCOUNT_TYPE, account.type);
            provider.insert(uri, values);
        } 
 
        public static Uri insert(ContentProviderClient provider, Uri uri,
                Account account, byte[] data) throws RemoteException {
            ContentValues values = new ContentValues();
            values.put(Columns.DATA, data);
            values.put(Columns.ACCOUNT_NAME, account.name);
            values.put(Columns.ACCOUNT_TYPE, account.type);
            return provider.insert(uri, values);
        } 
 
        public static void update(ContentProviderClient provider, Uri uri, byte[] data)
                throws RemoteException { 
            ContentValues values = new ContentValues();
4
CodeRank
This code example shows how to use the following methods:insert
    public int hashCode() { 
        return mUnderlying.hashCode();
    } 
 
    public final Uri insert(Uri url, ContentValues initialValues) throws RemoteException {
        return mUnderlying.insert(url, initialValues);
    } 
 
    public final AssetFileDescriptor openAssetFile(Uri url, String mode) throws RemoteException, FileNotFoundException {
        return mUnderlying.openAssetFile(url, mode);
    } 
 
    public final ParcelFileDescriptor openFile(Uri url, String mode) throws RemoteException, FileNotFoundException {
        return mUnderlying.openFile(url, mode);
    } 
 
    //    public final Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal) throws RemoteException { 
    //        return mUnderlying.query(url, projection, selection, selectionArgs, sortOrder, cancellationSignal); 
    //    } 
 
4
CodeRank
This code example shows how to use the following methods:insert
		super(DiscussionsProvider.class, DiscussionsProvider.class.getName());
	} 
 
	static Uri insertValidValue(final int valueId, final ContentProvider provider) {
 
		TopicsTableTest.insertValidValue(TOPIC_ID, provider);
		return provider.insert(tableUri, getTestValue(valueId));
	} 
 
	private static ContentValues getTestValue(final int valueId) {
 
		final ContentValues cv = new ContentValues();
		cv.put(Points.Columns.ID, Integer.valueOf(valueId));
		cv.put(Points.Columns.AGREEMENT_CODE, 0);
		cv.put(Points.Columns.EXPANDED, false);
		cv.put(Points.Columns.GROUP_ID, GROUP_ID);
		cv.put(Points.Columns.NUMBERED_POINT, "112");
		cv.put(Points.Columns.PERSON_ID, Integer.valueOf(PERSON_ID));
		cv.put(Points.Columns.NAME, "My point");
		cv.put(Points.Columns.SHARED_TO_PUBLIC, true);
4
CodeRank
This code example shows how to use the following methods:insert
		super(DiscussionsProvider.class, DiscussionsProvider.class.getName());
	} 
 
	public static Uri insertValidValue(final int valueId, final ContentProvider provider) {
 
		return provider.insert(tableUri, getTestValue(valueId));
	} 
 
	static ContentValues getTestValue(final int valueId) {
 
		final ContentValues cv = new ContentValues();
		// cv.put(Persons.Columns.AVATAR, new byte[] {}); 
		cv.put(Persons.Columns.ID, Integer.valueOf(valueId));
		cv.put(Persons.Columns.NAME, "person name");
		cv.put(Persons.Columns.EMAIL, "person@mail");
		cv.put(Persons.Columns.COLOR, Color.CYAN);
		cv.put(Persons.Columns.ONLINE, false);
		return cv;
	} 
 
4
CodeRank
insert Method Overview
Implement this to handle requests to insert a new row.
See Code Examples for other Android ContentProvider Methods: