Java Code Examples for android.content.ContentProviderClient#query()
The following examples show how to use
android.content.ContentProviderClient#query() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyncStateContract.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Get the sync state that is associated with the account or null. * @param provider the {@link ContentProviderClient} that is to be used to communicate * with the {@link android.content.ContentProvider} that contains the sync state. * @param uri the uri of the sync state * @param account the {@link Account} whose sync state should be returned * @return the sync state or null if there is no sync state associated with the account * @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(); } return null; }
Example 2
Source File: SyncStateContract.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public static Pair<Uri, byte[]> getWithUri(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); if (c == null) { throw new RemoteException(); } try { if (c.moveToNext()) { long rowId = c.getLong(1); byte[] blob = c.getBlob(c.getColumnIndexOrThrow(Columns.DATA)); return Pair.create(ContentUris.withAppendedId(uri, rowId), blob); } } finally { c.close(); } return null; }
Example 3
Source File: RecentLoader.java From FireFiles with Apache License 2.0 | 6 votes |
public void runInternal() { ContentProviderClient client = null; try { client = DocumentsApplication.acquireUnstableProviderOrThrow( getContext().getContentResolver(), authority); final Uri uri = DocumentsContract.buildRecentDocumentsUri(authority, rootId); final Cursor cursor = client.query( uri, null, null, null, DirectoryLoader.getQuerySortOrder(mSortOrder)); mWithRoot = new RootCursorWrapper(authority, rootId, cursor, MAX_DOCS_FROM_ROOT); } catch (Exception e) { Log.w(TAG, "Failed to load " + authority + ", " + rootId, e); } finally { ContentProviderClientCompat.releaseQuietly(client); } set(mWithRoot); mFirstPassLatch.countDown(); if (mFirstPassDone) { onContentChanged(); } }
Example 4
Source File: DocumentInfo.java From FireFiles with Apache License 2.0 | 6 votes |
public void updateFromUri(ContentResolver resolver, Uri uri) throws FileNotFoundException { ContentProviderClient client = null; Cursor cursor = null; try { client = DocumentsApplication.acquireUnstableProviderOrThrow( resolver, uri.getAuthority()); cursor = client.query(uri, null, null, null, null); if (!cursor.moveToFirst()) { throw new FileNotFoundException("Missing details for " + uri); } updateFromCursor(cursor, uri.getAuthority()); } catch (Throwable t) { throw asFileNotFoundException(t); } finally { IoUtils.closeQuietly(cursor); ContentProviderClientCompat.releaseQuietly(client); } }
Example 5
Source File: RecentLoader.java From FireFiles with Apache License 2.0 | 6 votes |
public void runInternal() { ContentProviderClient client = null; try { client = DocumentsApplication.acquireUnstableProviderOrThrow( getContext().getContentResolver(), authority); final Uri uri = DocumentsContract.buildRecentDocumentsUri(authority, rootId); final Cursor cursor = client.query( uri, null, null, null, DirectoryLoader.getQuerySortOrder(mSortOrder)); mWithRoot = new RootCursorWrapper(authority, rootId, cursor, MAX_DOCS_FROM_ROOT); } catch (Exception e) { Log.w(TAG, "Failed to load " + authority + ", " + rootId, e); } finally { ContentProviderClientCompat.releaseQuietly(client); } set(mWithRoot); mFirstPassLatch.countDown(); if (mFirstPassDone) { onContentChanged(); } }
Example 6
Source File: DocumentInfo.java From FireFiles with Apache License 2.0 | 6 votes |
public void updateFromUri(ContentResolver resolver, Uri uri) throws FileNotFoundException { ContentProviderClient client = null; Cursor cursor = null; try { client = DocumentsApplication.acquireUnstableProviderOrThrow( resolver, uri.getAuthority()); cursor = client.query(uri, null, null, null, null); if (!cursor.moveToFirst()) { throw new FileNotFoundException("Missing details for " + uri); } updateFromCursor(cursor, uri.getAuthority()); } catch (Throwable t) { throw asFileNotFoundException(t); } finally { IoUtils.closeQuietly(cursor); ContentProviderClientCompat.releaseQuietly(client); } }
Example 7
Source File: RecentLoader.java From FireFiles with Apache License 2.0 | 6 votes |
public void runInternal() { ContentProviderClient client = null; try { client = DocumentsApplication.acquireUnstableProviderOrThrow( getContext().getContentResolver(), authority); final Uri uri = DocumentsContract.buildRecentDocumentsUri(authority, rootId); final Cursor cursor = client.query( uri, null, null, null, DirectoryLoader.getQuerySortOrder(mSortOrder)); mWithRoot = new RootCursorWrapper(authority, rootId, cursor, MAX_DOCS_FROM_ROOT); } catch (Exception e) { Log.w(TAG, "Failed to load " + authority + ", " + rootId, e); } finally { ContentProviderClientCompat.releaseQuietly(client); } set(mWithRoot); mFirstPassLatch.countDown(); if (mFirstPassDone) { onContentChanged(); } }
Example 8
Source File: DocumentInfo.java From FireFiles with Apache License 2.0 | 6 votes |
public void updateFromUri(ContentResolver resolver, Uri uri) throws FileNotFoundException { ContentProviderClient client = null; Cursor cursor = null; try { client = DocumentsApplication.acquireUnstableProviderOrThrow( resolver, uri.getAuthority()); cursor = client.query(uri, null, null, null, null); if (!cursor.moveToFirst()) { throw new FileNotFoundException("Missing details for " + uri); } updateFromCursor(cursor, uri.getAuthority()); } catch (Throwable t) { throw asFileNotFoundException(t); } finally { IoUtils.closeQuietly(cursor); ContentProviderClientCompat.releaseQuietly(client); } }
Example 9
Source File: PluginProviderClient2.java From springreplugin with Apache License 2.0 | 6 votes |
/** * 调用插件里的Provider * * @see android.content.ContentProviderClient#query(Uri, String[], String, String[], String) */ public static Cursor query(Context c, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { ContentProviderClient client = PluginProviderClient.acquireContentProviderClient(c, ""); if (client != null) { try { Uri toUri = toCalledUri(c, uri); return client.query(toUri, projection, selection, selectionArgs, sortOrder); } catch (RemoteException e) { if (LogDebug.LOG) { Log.d(TAG, e.toString()); } } } if (LogDebug.LOG) { Log.d(TAG, String.format("call query1 %s fail", uri.toString())); } return null; }
Example 10
Source File: PluginProviderClient2.java From springreplugin with Apache License 2.0 | 6 votes |
/** * 调用插件里的Provider * * @see android.content.ContentProviderClient#query(Uri, String[], String, String[], String, CancellationSignal) */ @TargetApi(16) public static Cursor query(Context c, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal) { ContentProviderClient client = PluginProviderClient.acquireContentProviderClient(c, ""); if (client != null) { try { Uri toUri = toCalledUri(c, uri); return client.query(toUri, projection, selection, selectionArgs, sortOrder, cancellationSignal); } catch (RemoteException e) { if (LogDebug.LOG) { Log.d(TAG, e.toString()); } } } if (LogDebug.LOG) { Log.d(TAG, String.format("call query2 %s fail", uri.toString())); } return null; }
Example 11
Source File: AbstractContentProviderStub.java From DroidPlugin with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { String targetAuthority = uri.getQueryParameter(Env.EXTRA_TARGET_AUTHORITY); if (!TextUtils.isEmpty(targetAuthority) && !TextUtils.equals(targetAuthority, uri.getAuthority())) { ContentProviderClient client = getContentProviderClient(targetAuthority); try { return client.query(buildNewUri(uri, targetAuthority), projection, selection, selectionArgs, sortOrder); } catch (RemoteException e) { handleExpcetion(e); } } return null; }
Example 12
Source File: FileUtil.java From Hentoid with Apache License 2.0 | 5 votes |
static List<DocumentFile> listDocumentFiles( @NonNull final Context context, @NonNull final DocumentFile parent, @NonNull final ContentProviderClient client, final FileHelper.NameFilter nameFilter, boolean listFolders, boolean listFiles) { final List<ImmutableTriple<Uri, String, Long>> results = new ArrayList<>(); final Uri searchUri = DocumentsContract.buildChildDocumentsUriUsingTree(parent.getUri(), DocumentsContract.getDocumentId(parent.getUri())); try (Cursor c = client.query(searchUri, new String[]{ DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_DISPLAY_NAME, DocumentsContract.Document.COLUMN_MIME_TYPE, DocumentsContract.Document.COLUMN_SIZE}, null, null, null)) { if (c != null) while (c.moveToNext()) { final String documentId = c.getString(0); final String documentName = c.getString(1); boolean isFolder = c.getString(2).equals(DocumentsContract.Document.MIME_TYPE_DIR); final Long documentSize = c.getLong(3); // FileProvider doesn't take query selection arguments into account, so the selection has to be done manually if ((null == nameFilter || nameFilter.accept(documentName)) && ((listFiles && !isFolder) || (listFolders && isFolder))) results.add(new ImmutableTriple<>(DocumentsContract.buildDocumentUriUsingTree(parent.getUri(), documentId), documentName, documentSize)); } } catch (Exception e) { Timber.w(e, "Failed query"); } return convertFromUris(context, results); }
Example 13
Source File: SyncAdapter.java From attendee-checkin with Apache License 2.0 | 4 votes |
private void syncCheckins(ContentProviderClient provider, String cookie) { Cursor cursor = null; try { cursor = provider.query(Table.ATTENDEE.getBaseUri(), new String[]{ Table.Attendee.ID, Table.Attendee.CHECKIN, Table.Attendee.EVENT_ID, }, Table.Attendee.CHECKIN_MODIFIED, null, null); if (0 == cursor.getCount()) { Log.d(TAG, "No checkin to sync."); return; } int syncCount = 0; while (cursor.moveToNext()) { String attendeeId = cursor.getString( cursor.getColumnIndexOrThrow(Table.Attendee.ID)); String eventId = cursor.getString( cursor.getColumnIndexOrThrow(Table.Attendee.EVENT_ID)); long checkin = cursor.getLong(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN)); long serverCheckin = postCheckIn(attendeeId, eventId, checkin == 0, cookie); if (serverCheckin >= 0) { ContentValues values = new ContentValues(); values.put(Table.Attendee.CHECKIN_MODIFIED, false); if (0 == serverCheckin) { values.putNull(Table.Attendee.CHECKIN); } else { values.put(Table.Attendee.CHECKIN, serverCheckin); } provider.update(Table.ATTENDEE.getItemUri(eventId, attendeeId), values, null, null); ++syncCount; } } Log.d(TAG, syncCount + " checkin(s) synced."); } catch (RemoteException e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } }