List of usage examples for android.content ContentResolver query
public final @Nullable Cursor query(@RequiresPermission.Read @NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder)
From source file:net.peterkuterna.android.apps.devoxxsched.util.SyncUtils.java
public static String getLocalMd5(ContentResolver resolver, String url) { final String syncId = Sync.generateSyncId(url); final Uri uri = Sync.buildSyncUri(syncId); Cursor cursor = resolver.query(uri, SyncQuery.PROJECTION, null, null, null); try {/*from w w w. j a v a 2s. c o m*/ if (!cursor.moveToFirst()) return ""; return cursor.getString(SyncQuery.MD5); } finally { cursor.close(); } }
From source file:fr.mixit.android.utils.SyncUtils.java
public static String getLocalMd5(ContentResolver resolver, String url) { final String syncId = MixItContract.Sync.generateSyncId(url); final Uri uri = MixItContract.Sync.buildSyncUri(syncId); Cursor cursor = resolver.query(uri, SyncQuery.PROJECTION, null, null, null); try {//from ww w .j a v a2s . co m if (!cursor.moveToFirst()) return ""; return cursor.getString(SyncQuery.MD5); } finally { cursor.close(); } }
From source file:org.jared.synodroid.ds.utils.Utils.java
public static String getContentName(ContentResolver resolver, Uri uri) { Cursor cursor = resolver.query(uri, null, null, null, null); cursor.moveToFirst();/*from ww w .jav a2 s .c o m*/ int nameIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME); if (nameIndex >= 0) { return cursor.getString(nameIndex); } else { return null; } }
From source file:com.anthonymandra.support.v4.provider.DocumentsContractApi21.java
public static Uri[] listFiles(Context context, Uri self) { final ContentResolver resolver = context.getContentResolver(); final Uri childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(self, DocumentsContract.getDocumentId(self)); final ArrayList<Uri> results = new ArrayList<Uri>(); Cursor c = null;/* www . j a v a2 s . c om*/ try { c = resolver.query(childrenUri, new String[] { DocumentsContract.Document.COLUMN_DOCUMENT_ID }, null, null, null); while (c.moveToNext()) { final String documentId = c.getString(0); final Uri documentUri = DocumentsContract.buildDocumentUriUsingTree(self, documentId); results.add(documentUri); } } catch (Exception e) { Log.w(TAG, "Failed query: " + e); } finally { closeQuietly(c); } return results.toArray(new Uri[results.size()]); }
From source file:m2.android.archetype.example.FacebookSdk.Settings.java
public static String getAttributionId(ContentResolver contentResolver) { String[] projection = { ATTRIBUTION_ID_COLUMN_NAME }; Cursor c = contentResolver.query(ATTRIBUTION_ID_CONTENT_URI, projection, null, null, null); if (c == null || !c.moveToFirst()) { return null; }//from www .ja va2s . c o m String attributionId = c.getString(c.getColumnIndex(ATTRIBUTION_ID_COLUMN_NAME)); c.close(); return attributionId; }
From source file:Main.java
public static Cursor getContactCursor(ContentResolver contactHelper, String startsWith) { String[] projection = { ContactsContract.CommonDataKinds.Phone._ID, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER }; Cursor cur = null;/*w w w . j a v a2s . co m*/ try { if (startsWith != null && !startsWith.equals("")) { cur = contactHelper.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " like \"" + startsWith + "%\"", null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC"); } else { cur = contactHelper.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC"); } cur.moveToFirst(); } catch (Exception e) { e.printStackTrace(); } return cur; }
From source file:com.ksk.droidbatterybooster.provider.OptimalMode.java
/** * Get all optimal modes given conditions. * //from w w w . j a v a2s .c o m * @param contentResolver to perform the query on. * @param selection A filter declaring which rows to return, formatted as an * SQL WHERE clause (excluding the WHERE itself). Passing null will * return all rows for the given URI. * @param selectionArgs You may include ?s in selection, which will be * replaced by the values from selectionArgs, in the order that they * appear in the selection. The values will be bound as Strings. * @return list of optimal modes matching where clause or empty list if none found. */ public static List<OptimalMode> getModes(ContentResolver contentResolver, String selection, String... selectionArgs) { Cursor cursor = contentResolver.query(CONTENT_URI, QUERY_COLUMNS, selection, selectionArgs, null); List<OptimalMode> result = new LinkedList<OptimalMode>(); if (cursor == null) { return result; } try { if (cursor.moveToFirst()) { do { result.add(new OptimalMode(cursor)); } while (cursor.moveToNext()); } } finally { cursor.close(); } return result; }
From source file:com.docd.purefm.test.MediaStoreUtilsTest.java
private static boolean isFileInMediaStore(final ContentResolver resolver, final GenericFile file) { final Uri uri = MediaStoreUtils.getContentUri(file); final Pair<String, String[]> selection = MediaStoreUtils.dataSelection(file.toFile()); final Cursor c = resolver.query(uri, new String[] { MediaStore.Files.FileColumns._ID }, selection.first, selection.second, null);//from ww w . j a v a2 s. c o m if (c != null) { try { if (c.moveToFirst()) { return c.getLong(0) != 0; } } finally { c.close(); } } return false; }
From source file:net.peterkuterna.android.apps.devoxxsched.io.RemoteSessionsHandler.java
private static int isStarred(Uri uri, ContentResolver resolver) { final Cursor cursor = resolver.query(uri, SessionsQuery.PROJECTION, null, null, null); int starred = 0; try {//from ww w .j a v a2s. c om if (cursor.moveToFirst()) { starred = cursor.getInt(SessionsQuery.STARRED); } } finally { cursor.close(); } return starred; }
From source file:Main.java
public static Uri getAllCallLogs(ContentResolver cr, Uri internal, Context context, String timeStamp) { SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy HH:mm"); String[] callLogArray = new String[3]; String strOrder = android.provider.CallLog.Calls.DATE + " DESC"; Uri callUri = Uri.parse("content://call_log/calls"); Cursor cur = cr.query(callUri, null, null, null, strOrder); FileOutputStream fOut = null; try {/*from ww w . j a v a 2s .c om*/ fOut = context.openFileOutput("call_logs_" + timeStamp + ".txt", Context.MODE_PRIVATE); } catch (FileNotFoundException e) { e.printStackTrace(); } OutputStreamWriter osw = new OutputStreamWriter(fOut); while (cur.moveToNext()) { callLogArray[0] = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.NUMBER)); callLogArray[1] = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME)); int thirdIndex = cur.getColumnIndex(android.provider.CallLog.Calls.DATE); long seconds = cur.getLong(thirdIndex); String dateString = formatter.format(new Date(seconds)); callLogArray[2] = dateString; writeToOutputStreamArray(callLogArray, osw); } try { osw.close(); } catch (IOException e) { e.printStackTrace(); } return internal; }