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:myblog.richard.vewe.launcher3.LauncherApplication.java
public LockAndReason getLockAndReason(String pkgName) { LockAndReason lr = new LockAndReason(false, null); ContentResolver resolver = getContentResolver(); String selection = UsersContract.TableApplist.Column.PKG + "=" + pkgName; Cursor cursor = resolver.query(UsersContract.TableApplist.DIGA_URI, new String[] { UsersContract.TableApplist.Column.LOCK, UsersContract.TableApplist.Column.REASON }, selection, null, null);/*from www . j av a 2 s . com*/ if (cursor == null || cursor.getCount() != 1) { Log.e(tag, "could not query " + pkgName + " from applist"); return lr; } cursor.moveToFirst(); App app = new App(cursor); cursor.close(); lr.locked = app.isLocked(); lr.reason = app.getReason(); return lr; }
From source file:com.bangz.smartmute.services.LocationMuteService.java
/** * Add all activated location position to Google geofencing services * TODO: adjust algorithm to fit geofencing service no more 100 geofences in one app. *//*w w w.j av a2s. co m*/ private void handleStartGeofences() { LogUtils.LOGD(TAG, "Handling start geofences..."); int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (result != ConnectionResult.SUCCESS) { //TODO: notfiy user that we need Google Play Services. return; } if (PrefUtils.isEnableSmartMute(this) == false) { LogUtils.LOGD(TAG, "Smart Mute is disabled by user. quit start geofence"); return; } ContentResolver cr = getContentResolver(); Cursor cursor = cr.query(RulesColumns.CONTENT_URI, PROJECTS, SELECT_STRING, DEF_SELECT_ARGUMENTS, RulesColumns._ID); if (cursor.getCount() == 0) { LogUtils.LOGD(TAG, "\tNo record..., Leave handling start geofences. "); cursor.close(); return; } List<Geofence> geofences = fillGeofences(cursor); // no long need database cursor.close(); boolean b = addGeofences(geofences); LogUtils.LOGD(TAG, (b ? "Successful" : "Failed") + " started geofence."); }
From source file:com.securecomcode.text.contacts.ContactAccessor.java
public List<String> getNumbersForThreadSearchFilter(String constraint, ContentResolver contentResolver) { LinkedList<String> numberList = new LinkedList<String>(); Cursor cursor = null;/*from w w w . j a v a 2 s .c o m*/ try { cursor = contentResolver.query(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(constraint)), null, null, null, null); while (cursor != null && cursor.moveToNext()) { numberList.add(cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER))); } } finally { if (cursor != null) cursor.close(); } return numberList; }
From source file:com.jackie.sunshine.app.sync.SunshineSyncAdapter.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city * @param lon the longitude of the city * @return the row ID of the added location. *//*from w w w . java2 s. c o m*/ private long addLocation(String locationSetting, String cityName, double lat, double lon) { ContentResolver locationResolver = getContext().getContentResolver(); Cursor locationCursor = locationResolver.query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); long locationId; // Students: First, check if the location with this city name exists in the db if (locationCursor != null && locationCursor.moveToFirst()) { // If it exists, return the current ID locationId = locationCursor.getLong(locationCursor.getColumnIndex(LocationEntry._ID)); } else { // Otherwise, insert it using the content resolver and the base URI ContentValues locationValues = new ContentValues(); locationValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(LocationEntry.COLUMN_COORD_LONG, lon); Uri insertUri = locationResolver.insert(LocationEntry.CONTENT_URI, locationValues); locationId = ContentUris.parseId(insertUri); } if (locationCursor != null && !locationCursor.isClosed()) { locationCursor.close(); } return locationId; }
From source file:com.polyvi.xface.extension.XMessagingExt.java
/** * ????//from w ww . j a v a 2 s . c om */ private int getRecordCount(Uri queryUri, String selection, String[] selectionArgs) throws InvalidParameterException { ContentResolver resolver = getContext().getContentResolver(); Cursor cursor = resolver.query(queryUri, new String[] { BaseColumns._ID }, selection, selectionArgs, null); if (null == cursor) { throw new InvalidParameterException(); } final int count = cursor.getCount(); cursor.close(); return count; }
From source file:com.akop.bach.fragment.playstation.TrophiesFragment.java
@Override protected Cursor getIconCursor() { if (getActivity() == null) return null; ContentResolver cr = getActivity().getContentResolver(); return cr.query(Trophies.CONTENT_URI, new String[] { Trophies._ID, Trophies.ICON_URL }, Trophies.GAME_ID + "=" + mTitleId + " AND (" + Trophies.EARNED + " != 0 OR " + Trophies.EARNED_TEXT + " IS NOT NULL)", null, Trophies.DEFAULT_SORT_ORDER); }
From source file:com.google.samples.apps.sergio.service.SessionAlarmService.java
private void scheduleAllStarredBlocks() { final ContentResolver cr = getContentResolver(); final Cursor c = cr.query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, new String[] { "distinct " + ScheduleContract.Sessions.SESSION_START, ScheduleContract.Sessions.SESSION_END, ScheduleContract.Sessions.SESSION_IN_MY_SCHEDULE }, null, null, null);/*from w w w. j a v a2s .co m*/ if (c == null) { return; } while (c.moveToNext()) { final long sessionStart = c.getLong(0); final long sessionEnd = c.getLong(1); scheduleAlarm(sessionStart, sessionEnd, UNDEFINED_ALARM_OFFSET); } }
From source file:com.akop.bach.fragment.xboxlive.MessagesFragment.java
@Override public void onCreate(Bundle state) { super.onCreate(state); if (mAccount == null) { Bundle args = getArguments();/* w ww . j a v a 2s . c om*/ ContentResolver cr = getActivity().getContentResolver(); mAccount = (XboxLiveAccount) args.getParcelable("account"); mTitleId = getFirstTitleId(cr.query(Messages.CONTENT_URI, new String[] { Messages._ID, }, Messages.ACCOUNT_ID + "=" + mAccount.getId(), null, Messages.DEFAULT_SORT_ORDER)); } if (state != null && state.containsKey("account")) { mAccount = (XboxLiveAccount) state.getParcelable("account"); mTitleId = state.getLong("titleId"); } setHasOptionsMenu(true); }
From source file:com.germainz.identiconizer.services.IdenticonCreationService.java
private void setContactPhoto(ContentResolver resolver, byte[] bytes, int personId, String name) { ContentValues values = new ContentValues(); int photoRow = -1; String where = ContactsContract.Data.RAW_CONTACT_ID + " == " + String.valueOf(personId) + " AND " + ContactsContract.Data.MIMETYPE + "=='" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'"; Cursor cursor = resolver.query(ContactsContract.Data.CONTENT_URI, null, where, null, null); int idIdx = cursor.getColumnIndexOrThrow(ContactsContract.Data._ID); if (cursor.moveToFirst()) { photoRow = cursor.getInt(idIdx); }//from w ww . j a va 2 s .com cursor.close(); if (photoRow >= 0) { final String selection = ContactsContract.Data.RAW_CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; final String[] selectionArgs = new String[] { String.valueOf(personId), ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE }; values.put(ContactsContract.Data.RAW_CONTACT_ID, personId); values.put(ContactsContract.Data.IS_PRIMARY, 1); values.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1); values.put(ContactsContract.CommonDataKinds.Photo.PHOTO, bytes); values.put("skip_processing", "skip_processing"); // We're not using applyBatch because of the 1024K limit of the transaction buffer, // which isn't enough when we're using a large identicon size and certain styles (e.g. // the Spirograph style, which occupies roughly that much on its own when the size is // set to 720x720.) if (getContentResolver().update(ContactsContract.Data.CONTENT_URI, values, selection, selectionArgs) != 1) mUpdateErrors.add(new ContactInfo(personId, name, bytes.length)); } else { values.put(ContactsContract.Data.RAW_CONTACT_ID, personId); values.put(ContactsContract.Data.IS_PRIMARY, 1); values.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1); values.put(ContactsContract.CommonDataKinds.Photo.PHOTO, bytes); values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE); values.put("skip_processing", "skip_processing"); if (getContentResolver().insert(ContactsContract.Data.CONTENT_URI, values) == null) mInsertErrors.add(new ContactInfo(personId, name, bytes.length)); } }
From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java
/** * ????/*from w w w .j ava 2 s .c o m*/ */ private int getRecordCount(Uri queryUri, String selection, String[] selectionArgs) throws InvalidParameterException { ContentResolver resolver = mContext.getContentResolver(); Cursor cursor = resolver.query(queryUri, new String[] { BaseColumns._ID }, selection, selectionArgs, null); if (null == cursor) { throw new InvalidParameterException(); } final int count = cursor.getCount(); cursor.close(); return count; }