List of usage examples for android.content ContentProviderClient query
public @Nullable Cursor query(@NonNull Uri url, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) throws RemoteException
From source file:edu.mit.mobile.android.locast.data.tags.TaggableUtils.java
public static Set<String> getTags(ContentProviderClient cpc, Uri tagDir) throws RemoteException { final Set<String> tags = new HashSet<String>(); final Cursor c = cpc.query(tagDir, TAG_PROJECTION, null, null, null); try {// w w w .j av a 2 s.co m final int tagNameCol = c.getColumnIndexOrThrow(Tag.COL_NAME); while (c.moveToNext()) { tags.add(c.getString(tagNameCol)); } } finally { c.close(); } return tags; }
From source file:at.bitfire.ical4android.AndroidCalendar.java
public static AndroidCalendar findByID(Account account, ContentProviderClient provider, AndroidCalendarFactory factory, long id) throws FileNotFoundException, CalendarStorageException { @Cleanup/*from ww w .ja v a 2 s . c om*/ EntityIterator iterCalendars = null; try { iterCalendars = CalendarContract.CalendarEntity.newEntityIterator(provider.query( syncAdapterURI(ContentUris.withAppendedId(CalendarContract.CalendarEntity.CONTENT_URI, id), account), null, null, null, null)); } catch (RemoteException e) { throw new CalendarStorageException("Couldn't query calendars", e); } if (iterCalendars.hasNext()) { ContentValues values = iterCalendars.next().getEntityValues(); AndroidCalendar calendar = factory.newInstance(account, provider, values.getAsLong(Calendars._ID)); calendar.populate(values); return calendar; } throw new FileNotFoundException(); }
From source file:at.bitfire.davdroid.resource.LocalTaskList.java
public static LocalTaskList[] findAll(Account account, ContentProviderClient providerClient) throws RemoteException { @Cleanup/* w w w . j a va 2 s. com*/ Cursor cursor = providerClient.query(taskListsURI(account), new String[] { TaskContract.TaskLists._ID, TaskContract.TaskLists._SYNC_ID }, null, null, null); LinkedList<LocalTaskList> taskList = new LinkedList<>(); while (cursor != null && cursor.moveToNext()) taskList.add(new LocalTaskList(account, providerClient, cursor.getInt(0), cursor.getString(1))); return taskList.toArray(new LocalTaskList[taskList.size()]); }
From source file:at.bitfire.ical4android.AndroidCalendar.java
public static AndroidCalendar[] find(Account account, ContentProviderClient provider, AndroidCalendarFactory factory, String where, String whereArgs[]) throws CalendarStorageException { @Cleanup//w w w .j av a 2s . c om EntityIterator iterCalendars = null; try { iterCalendars = CalendarContract.CalendarEntity.newEntityIterator( provider.query(syncAdapterURI(CalendarContract.CalendarEntity.CONTENT_URI, account), null, where, whereArgs, null)); } catch (RemoteException e) { throw new CalendarStorageException("Couldn't query calendars", e); } List<AndroidCalendar> calendars = new LinkedList<>(); while (iterCalendars.hasNext()) { ContentValues values = iterCalendars.next().getEntityValues(); AndroidCalendar calendar = factory.newInstance(account, provider, values.getAsLong(Calendars._ID)); calendar.populate(values); calendars.add(calendar); } return calendars.toArray(factory.newArray(calendars.size())); }
From source file:com.rukman.emde.smsgroups.platform.GMSContactOperations.java
/** * Find the group whose SOURCE_ID column matches the parameter. * //from ww w . j a va2 s . c o m * @param provider - ContentProviderClient * @param account - User account * @param sourceId - Cloud Id of the group. * @return Cursor object returned from query with projection: * new String[] { RawContacts._ID, RawContacts.SOURCE_ID }; */ public static Cursor findGroupInContacts(ContentProviderClient provider, Account account, String sourceId) { Cursor cursor = null; try { Uri uri = RawContacts.CONTENT_URI.buildUpon() .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, GMSApplication.ACCOUNT_TYPE).build(); cursor = provider.query(uri, new String[] { RawContacts._ID, RawContacts.SOURCE_ID }, RawContacts.SOURCE_ID + "=?", new String[] { sourceId }, null); return cursor; } catch (RemoteException e) { e.printStackTrace(); } return cursor; }
From source file:Main.java
/** * Try to get the exif orientation of the passed image uri * /*www. j av a2 s . c om*/ * @param context * @param uri * @return */ public static int getExifOrientation(Context context, Uri uri) { final String scheme = uri.getScheme(); ContentProviderClient provider = null; if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) { return getExifOrientation(uri.getPath()); } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) { try { provider = context.getContentResolver().acquireContentProviderClient(uri); } catch (SecurityException e) { return 0; } if (provider != null) { Cursor result; try { result = provider.query(uri, new String[] { Images.ImageColumns.ORIENTATION, Images.ImageColumns.DATA }, null, null, null); } catch (Exception e) { e.printStackTrace(); return 0; } if (result == null) { return 0; } int orientationColumnIndex = result.getColumnIndex(Images.ImageColumns.ORIENTATION); int dataColumnIndex = result.getColumnIndex(Images.ImageColumns.DATA); try { if (result.getCount() > 0) { result.moveToFirst(); int rotation = 0; if (orientationColumnIndex > -1) { rotation = result.getInt(orientationColumnIndex); } if (dataColumnIndex > -1) { String path = result.getString(dataColumnIndex); rotation |= getExifOrientation(path); } return rotation; } } finally { result.close(); } } } return 0; }
From source file:Main.java
/** * Try to get the exif orientation of the passed image uri * * @param context/* ww w. j a v a2 s. com*/ * @param uri * @return */ public static int getExifOrientation(Context context, Uri uri) { final String scheme = uri.getScheme(); ContentProviderClient provider = null; if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) { return getExifOrientation(uri.getPath()); } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) { try { provider = context.getContentResolver().acquireContentProviderClient(uri); } catch (SecurityException e) { return 0; } if (provider != null) { Cursor result; try { result = provider.query(uri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.Images.ImageColumns.DATA }, null, null, null); } catch (Exception e) { e.printStackTrace(); return 0; } if (result == null) { return 0; } int orientationColumnIndex = result.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION); int dataColumnIndex = result.getColumnIndex(MediaStore.Images.ImageColumns.DATA); try { if (result.getCount() > 0) { result.moveToFirst(); int rotation = 0; if (orientationColumnIndex > -1) { rotation = result.getInt(orientationColumnIndex); } if (dataColumnIndex > -1) { String path = result.getString(dataColumnIndex); rotation |= getExifOrientation(path); } return rotation; } } finally { result.close(); } } } return 0; }
From source file:at.bitfire.davdroid.mirakel.resource.LocalCalendar.java
public static LocalCalendar[] findAll(Account account, ContentProviderClient providerClient, Context ctx) throws RemoteException { @Cleanup//from w ww. ja v a 2s .c om Cursor cursor = providerClient.query(calendarsURI(account), new String[] { Calendars._ID, Calendars.NAME }, Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null); LinkedList<LocalCalendar> calendars = new LinkedList<LocalCalendar>(); while (cursor != null && cursor.moveToNext()) calendars.add(new LocalCalendar(account, providerClient, cursor.getInt(0), cursor.getString(1), ctx)); return calendars.toArray(new LocalCalendar[0]); }
From source file:com.granita.icloudcalsync.resource.LocalCalendar.java
public static LocalCalendar[] findAll(Account account, ContentProviderClient providerClient) throws RemoteException { @Cleanup//from w w w . jav a2 s .co m Cursor cursor = providerClient.query(calendarsURI(account), new String[] { Calendars._ID, Calendars.NAME }, Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null); LinkedList<LocalCalendar> calendars = new LinkedList<>(); while (cursor != null && cursor.moveToNext()) calendars.add(new LocalCalendar(account, providerClient, cursor.getInt(0), cursor.getString(1))); return calendars.toArray(new LocalCalendar[0]); }
From source file:org.voidsink.anewjkuapp.calendar.CalendarUtils.java
public static Cursor loadEvent(ContentProviderClient mProvider, Uri calUri, String calendarId) { // The ID of the recurring event whose instances you are // searching/*from w w w . java2s. co m*/ // for in the Instances table String selection = CalendarContractWrapper.Events.CALENDAR_ID() + " = ?"; String[] selectionArgs = new String[] { calendarId }; try { return mProvider.query(calUri, EVENT_PROJECTION, selection, selectionArgs, null); } catch (RemoteException e) { return null; } }