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:com.goliathonline.android.kegbot.io.RemoteTapHandler.java
private static ContentValues queryTapDetails(Uri uri, ContentResolver resolver) { final ContentValues values = new ContentValues(); final Cursor cursor = resolver.query(uri, TapsQuery.PROJECTION, null, null, null); try {// w w w.j a v a 2s .c om if (cursor.moveToFirst()) { values.put(SyncColumns.UPDATED, cursor.getLong(TapsQuery.UPDATED)); } else { values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER); } } finally { cursor.close(); } return values; }
From source file:Main.java
public static Integer getTvhChannelIdFromChannelUri(Context context, Uri channelUri) { ContentResolver resolver = context.getContentResolver(); String[] projection = { Channels._ID, Channels.COLUMN_ORIGINAL_NETWORK_ID }; // TODO: Handle when more than 1, or 0 results come back try (Cursor cursor = resolver.query(channelUri, projection, null, null, null)) { while (cursor != null && cursor.moveToNext()) { return cursor.getInt(1); }/*w w w. j a v a 2 s . c o m*/ } return null; }
From source file:Main.java
public static int getChannelCount(ContentResolver resolver, String inputId) { Uri uri = TvContract.buildChannelsUriForInput(inputId); String[] projection = { TvContract.Channels._ID }; Cursor cursor = null;/*from www . j av a 2 s. c om*/ try { cursor = resolver.query(uri, projection, null, null, null); if (cursor != null) { return cursor.getCount(); } } finally { if (cursor != null) { cursor.close(); } } return 0; }
From source file:com.goliathonline.android.kegbot.io.RemoteDrinksHandler.java
private static ContentValues queryDrinkDetails(Uri uri, ContentResolver resolver) { final ContentValues values = new ContentValues(); final Cursor cursor = resolver.query(uri, SessionsQuery.PROJECTION, null, null, null); try {//from w ww . j a v a 2s .c om if (cursor.moveToFirst()) { values.put(SyncColumns.UPDATED, cursor.getLong(SessionsQuery.UPDATED)); values.put(Drinks.DRINK_STARRED, cursor.getInt(SessionsQuery.STARRED)); } else { values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER); } } finally { cursor.close(); } return values; }
From source file:Main.java
/** * get the sound list of the system/*from w ww . j a va2s .c om*/ */ public static ArrayList<String> getSystemRingList(Context con) { ArrayList<String> getArray = new ArrayList<String>(); ContentResolver cr = con.getContentResolver(); String[] cols = new String[] { MediaStore.Audio.Media.IS_RINGTONE, MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.DISPLAY_NAME }; Cursor cursor = cr.query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, cols, null, null, null); if (cursor.moveToFirst()) { do { if (cursor.getString(0).equals("1")) { getArray.add(cursor.getString(2)); } } while (cursor.moveToNext()); } return getArray; }
From source file:com.ksk.droidbatterybooster.provider.PowerSchedule.java
public static PowerSchedule getSchedule(ContentResolver contentResolver, long id) { Cursor cursor = contentResolver.query(getUri(id), QUERY_COLUMNS, null, null, null); PowerSchedule result = null;/* www . ja v a 2 s . c o m*/ if (cursor == null) { return result; } try { if (cursor.moveToFirst()) { result = new PowerSchedule(cursor); } } finally { cursor.close(); } return result; }
From source file:Main.java
public static Uri getAllContacts(ContentResolver cr, Uri internal, Context context, String timeStamp) { String[] contactsArray = new String[2]; Uri contactsUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; Cursor cur = cr.query(contactsUri, null, null, null, null); FileOutputStream fOut = null; try {//w w w.j a v a2s .c o m fOut = context.openFileOutput("contacts_" + timeStamp + ".txt", Context.MODE_PRIVATE); } catch (FileNotFoundException e) { e.printStackTrace(); } OutputStreamWriter osw = new OutputStreamWriter(fOut); while (cur.moveToNext()) { contactsArray[0] = cur .getString(cur.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)) .toString(); contactsArray[1] = cur .getString(cur.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER)); writeToOutputStreamArray(contactsArray, osw); } try { osw.close(); } catch (IOException e) { e.printStackTrace(); } return internal; }
From source file:Main.java
/** * @param context The {@link Context} to use. * @param name The name of the new playlist. * @return A new playlist ID./*w w w .jav a 2s . co m*/ */ public static final long createPlaylist(final Context context, final String name) { if (name != null && name.length() > 0) { final ContentResolver resolver = context.getContentResolver(); final String[] projection = new String[] { PlaylistsColumns.NAME }; final String selection = PlaylistsColumns.NAME + " = '" + name + "'"; Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, selection, null, null); if (cursor.getCount() <= 0) { final ContentValues values = new ContentValues(1); values.put(PlaylistsColumns.NAME, name); final Uri uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values); return Long.parseLong(uri.getLastPathSegment()); } if (cursor != null) { cursor.close(); cursor = null; } return -1; } return -1; }
From source file:com.anthonymandra.support.v4.provider.DocumentsContractApi19.java
public static boolean exists(Context context, Uri self) { final ContentResolver resolver = context.getContentResolver(); Cursor c = null;// w w w .j a va 2s.c o m try { c = resolver.query(self, new String[] { DocumentsContract.Document.COLUMN_DOCUMENT_ID }, null, null, null); return c.getCount() > 0; } catch (Exception e) { // Log.w(TAG, "Failed query: " + e); return false; } finally { closeQuietly(c); } }
From source file:Main.java
private static Bitmap rotateMediaImage(ContentResolver contentResolver, Uri uri, Bitmap image) throws FileNotFoundException { Cursor c = contentResolver.query(uri, null, null, null, null); try {//from ww w. j a va 2 s. c o m if (c != null) { if (c.moveToFirst()) { int index = c.getColumnIndex(ImageColumns.ORIENTATION); int degrees = index < 0 ? 0 : c.getInt(index); if (degrees != 0) { return rotate(image, degrees); } return image; } } } finally { if (c != null) { c.close(); } } return image; }