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:gov.wa.wsdot.android.wsdot.service.TravelTimesSyncService.java
/** * Check the travel times table for any starred entries. If we find some, save them * to a list so we can re-star those after we flush the database. *///from w w w . ja v a 2s . c om private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(TravelTimes.CONTENT_URI, new String[] { TravelTimes.TRAVEL_TIMES_ID }, TravelTimes.TRAVEL_TIMES_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
private static void addPhonesToContactEntry(ContentResolver cr, long personId, ContactEntry entry) throws ParseException { Cursor c = cr.query(Phones.CONTENT_URI, null, "person=" + personId, null, null); int numberIndex = c.getColumnIndexOrThrow(People.Phones.NUMBER); try {/*from w ww. ja va 2 s .c o m*/ while (c.moveToNext()) { PhoneNumber phoneNumber = new PhoneNumber(); cursorToContactsElement(phoneNumber, c, PROVIDER_TYPE_TO_ENTRY_PHONE); phoneNumber.setPhoneNumber(c.getString(numberIndex)); entry.addPhoneNumber(phoneNumber); } } finally { if (c != null) c.close(); } }
From source file:gov.wa.wsdot.android.wsdot.service.CamerasSyncService.java
/** * Check the camera table for any starred entries. If we find some, save them * to a list so we can re-star those cameras after we flush the database. *//* w w w.j a v a 2 s. c om*/ private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(Cameras.CONTENT_URI, new String[] { Cameras.CAMERA_ID }, Cameras.CAMERA_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesTerminalSailingSpaceSyncService.java
/** * Check the ferries terminal space sailing table for any starred entries. * If we find some, save them to a list so we can re-star those after we * flush the database./*from w w w.j a va 2s .c om*/ */ private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(FerriesTerminalSailingSpace.CONTENT_URI, new String[] { FerriesTerminalSailingSpace.TERMINAL_ID }, FerriesTerminalSailingSpace.TERMINAL_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
private static void addOrganizationsToContactEntry(ContentResolver cr, long personId, ContactEntry entry) throws ParseException { Cursor c = cr.query(Organizations.CONTENT_URI, null, "person=" + personId, null, null); try {//ww w . ja v a2 s . c om int companyIndex = c.getColumnIndexOrThrow(Organizations.COMPANY); int titleIndex = c.getColumnIndexOrThrow(Organizations.TITLE); while (c.moveToNext()) { Organization organization = new Organization(); cursorToContactsElement(organization, c, PROVIDER_TYPE_TO_ENTRY_ORGANIZATION); organization.setName(c.getString(companyIndex)); organization.setTitle(c.getString(titleIndex)); entry.addOrganization(organization); } } finally { if (c != null) c.close(); } }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesSchedulesSyncService.java
/** * Check the ferries schedules table for any starred entries. If we find some, save them * to a list so we can re-star those after we flush the database. *//*from w w w . j a v a 2s . c o m*/ private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(FerriesSchedules.CONTENT_URI, new String[] { FerriesSchedules.FERRIES_SCHEDULE_ID }, FerriesSchedules.FERRIES_SCHEDULE_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:com.rightscale.app.dashboard.ShowServerMonitoring.java
public Cursor produceContent(String tag) throws RestException { if (tag == MONITORS) { ContentResolver cr = getContentResolver(); String[] whereArgs = { _helper.getAccountId(), getServerId() }; return cr.query(_helper.getContentRoute("server_monitors"), Dashboard.SERVER_MONITORS_COLUMNS, "account_id = ? AND server_id = ?", whereArgs, null); } else {/*from w w w . jav a 2 s .c o m*/ return super.produceContent(tag); } }
From source file:com.fa.mastodon.activity.ComposeActivity.java
private static long getMediaSize(ContentResolver contentResolver, Uri uri) { long mediaSize; Cursor cursor = contentResolver.query(uri, null, null, null, null); if (cursor != null) { int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE); cursor.moveToFirst();/*from w w w . j ava 2s . c o m*/ mediaSize = cursor.getLong(sizeIndex); cursor.close(); } else { mediaSize = MEDIA_SIZE_UNKNOWN; } return mediaSize; }
From source file:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java
private void scheduleAllStarredMatches() { final ContentResolver cr = getContentResolver(); final Cursor c = cr.query(MatchContract.ReminderEntry.CONTENT_URI, new String[] { MatchContract.SeriesEntry.TABLE_NAME + "." + MatchContract.ReminderEntry._ID, MatchContract.ReminderEntry.COLUMN_SET_REMINDER, MatchContract.SeriesEntry.COLUMN_DATETIME }, REMINDER_ID_WHERE_CLAUSE, null, null); if (c == null) { return;//from w w w.j av a 2 s.c om } while (c.moveToNext()) { final long matchId = c.getInt(0); final boolean reminderSet = c.getInt(1) > 0; final long dateTime = c.getLong(2); LOGD(TAG, "getUTCTime: " + TimeUtils.getUTCTime() + " cursorTime: " + dateTime); if (reminderSet) { scheduleAlarm(matchId, dateTime); } } }
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
private static void addExtensionsToContactEntry(ContentResolver cr, long personId, ContactEntry entry) throws ParseException { Cursor c = cr.query(Extensions.CONTENT_URI, null, "person=" + personId, null, null); try {//from ww w . ja v a 2 s .com JSONObject jsonObject = new JSONObject(); int nameIndex = c.getColumnIndexOrThrow(Extensions.NAME); int valueIndex = c.getColumnIndexOrThrow(Extensions.VALUE); if (c.getCount() == 0) return; while (c.moveToNext()) { try { jsonObject.put(c.getString(nameIndex), c.getString(valueIndex)); } catch (JSONException e) { throw new ParseException("bad key or value", e); } } ExtendedProperty extendedProperty = new ExtendedProperty(); extendedProperty.setName("android"); final String jsonString = jsonObject.toString(); if (jsonString == null) { throw new ParseException( "unable to convert cursor into a JSON string, " + DatabaseUtils.dumpCursorToString(c)); } extendedProperty.setXmlBlob(jsonString); entry.addExtendedProperty(extendedProperty); } finally { if (c != null) c.close(); } }