ContentProvider query - 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 query 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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:query
	} 
 
	@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();
		} 
		return null; 
	} 
 
	@Override 
	public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
		try { 
			return mProvider.update(uri, values, selection, selectionArgs);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:query
    //    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); 
    //    } 
 
    public final Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sortOrder) throws RemoteException {
        return mUnderlying.query(url, projection, selection, selectionArgs, sortOrder);
    } 
 
    public final boolean release() { 
        return mUnderlying.release();
    } 
 
    public String toString() {
        return mUnderlying.toString();
    } 
 
    public final int update(Uri url, ContentValues values, String selection, String[] selectionArgs) throws RemoteException {
        return mUnderlying.update(url, values, selection, selectionArgs);
    } 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:query
This code example shows how to use the following methods:query
         * @throws RemoteException if there is a failure communicating with the remote 
         * {@link android.content.ContentProvider} 
         */ 
        public static byte[] get(ContentProviderClient provider, Uri uri,
                Account account) throws RemoteException {
            Cursor c = provider.query(uri, DATA_PROJECTION, SELECT_BY_ACCOUNT,
                    new String[]{account.name, account.type}, null);
 
            // Unable to query the provider 
            if (c == null) {
                throw new RemoteException();
            } 
 
            try { 
                if (c.moveToNext()) {
                    return c.getBlob(c.getColumnIndexOrThrow(Columns.DATA));
                } 
            } finally { 
                c.close();
            } 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:query
         * @throws RemoteException if there is a failure communicating with the remote 
         * {@link android.content.ContentProvider} 
         */ 
        public static byte[] get(ContentProviderClient provider, Uri uri,
                Account account) throws RemoteException {
            Cursor c = provider.query(uri, DATA_PROJECTION, SELECT_BY_ACCOUNT,
                    new String[]{account.name, account.type}, null);
            try { 
                if (c.moveToNext()) {
                    return c.getBlob(c.getColumnIndexOrThrow(Columns.DATA));
                } 
            } finally { 
                c.close();
            } 
            return null; 
        } 
 
        /** 
         * Assigns the data array as the sync state for the given account. 
         * @param provider the {@link ContentProviderClient} that is to be used to communicate 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:query
			contentProvider = getProvider();
 
			Uri uri = Uri
					.parse("content://mobile.android.ch11.regioncontentprovider/code/024");
 
			cursor = contentProvider.query(uri, null, null, null, null);
			if (cursor.moveToFirst())
			{ 
				city = cursor.getString(cursor.getColumnIndex("city_name"));
			} 
		} 
		catch (Exception e)
		{ 
			// TODO: handle exception 
		} 
 
	} 
 
	public void testCursor() throws Exception 
	{ 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:query
	// Long 
	// 
	public static long getLong(ContentProvider provider, Uri uri, String key) {
		long value = -1L;
 
		Cursor cur = provider.query(uri, null, null, null, null);
		if (cur != null) {
			value = getLong(cur, key);
			cur.close();
		} 
		return value;
	} 
 
	public static long getLong(ContentProvider provider, Uri contentUri,
			long id, String key) {
		return getLong(provider, ContentUris.withAppendedId(contentUri, id),
				key);
	} 
 
	public static long getLong(ContentResolver resolver, Uri uri, String key) {
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:query
        ); 
 
        ContentProviderClient client = getContentResolver().acquireContentProviderClient(chUri);
        ContentProvider provider = client.getLocalContentProvider();
 
        Cursor c = provider.query(chUri, null, null, null, null);
 
        character = new com.cthos.pfpt.core.Character(c, this);
 
        startManagingCursor(c);
    } 
 
    protected void _initButtons() { 
        Button saveButton = (Button) findViewById(R.id.adjust_stats_save_button);
        saveButton.setOnClickListener(saveClicked);
    } 
 
    protected void _initCurrentSettings() { 
        EditText hpField = (EditText) findViewById(R.id.adjust_stats_additional_hp);
        long additionalHp = character.getAdditionalHP();
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:query
	// Long 
	// 
	public static long getLong(ContentProvider provider, Uri uri, String key) {
		long value = -1L;
 
		Cursor cur = provider.query(uri, null, null, null, null);
		if (cur != null) {
			value = getLong(cur, key);
			cur.close();
		} 
		return value;
	} 
 
	public static long getLong(ContentProvider provider, Uri contentUri,
			long id, String key) {
		return getLong(provider, ContentUris.withAppendedId(contentUri, id),
				key);
	} 
 
	public static long getLong(ContentResolver resolver, Uri uri, String key) {
3
CodeRank
Experience pair programming with AI  Get Codota for Java
query Method Overview
Implement this to handle query requests from clients.
See Code Examples for other Android ContentProvider Methods: