ContentResolver query - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for ContentResolver query method.

This code example shows how to use the following methods:query
  } 
 
  public static Bitmap getLocalUserContactPhoto(Context context, Uri uri) {
    if (uri == null) return getDefaultContactPhoto(context);
 
    Bitmap contactPhoto = localUserContactPhotoCache.get(uri);
 
    if (contactPhoto == null) {
      Cursor cursor = context.getContentResolver().query(uri, CONTENT_URI_PROJECTION,
                                                         null, null, null); 
 
      if (cursor != null && cursor.moveToFirst()) {
        contactPhoto = getContactPhoto(context, Uri.withAppendedPath(Contacts.CONTENT_URI,
                                       cursor.getLong(0) + ""));
      } else { 
        contactPhoto = getDefaultContactPhoto(context);
      } 
 
      localUserContactPhotoCache.put(uri, contactPhoto);
    } 

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:query
		 
	} 
 
	private void setupSocialFeed() { 
		socialFeedUri = FeedProvider.SOCIAL_FEEDS_URI.buildUpon().appendPath(userId).build();
		socialFeed = SocialFeed.fromCursor(contentResolver.query(socialFeedUri, null, null, null, null));
	} 
	 
	public static SocialFeedItemListFragment newInstance(final String userId, final String username, final int currentState) {
		return new SocialFeedItemListFragment(userId, username, currentState);
	} 
	 
	@Override 
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.fragment_itemlist, null);
		itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
		itemList.setEmptyView(v.findViewById(R.id.empty_view));
		 
		itemList.setOnScrollListener(this);
		itemList.setAdapter(adapter);
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:query, openContactPhotoInputStream
    public ContactInfo loadContact(ContentResolver contentResolver, Uri contactUri) {
        ContactInfo contactInfo = new ContactInfo();
        long contactId = -1;
 
        // Load the display name for the specified person 
        Cursor cursor = contentResolver.query(contactUri,
                new String[]{Contacts._ID, Contacts.DISPLAY_NAME, Contacts.PHOTO_ID}, null, null, null);
        try { 
            if (cursor.moveToFirst()) {
                contactId = cursor.getLong(0);
                contactInfo.setDisplayName(cursor.getString(1));
                contactInfo.setPhotoId(cursor.getInt(2));
            } 
        } finally { 
            cursor.close();
        } 
 
        boolean modified=false;
        cursor = contentResolver.query(Phone.CONTENT_URI,
        		new String[]{Phone.NUMBER},

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:query
    } 
 
    public static Cursor query(Context context, ContentResolver resolver, Uri uri,
            String[] projection, String selection, String[] selectionArgs, String sortOrder) {
        try { 
            return resolver.query(uri, projection, selection, selectionArgs, sortOrder);
        } catch (SQLiteException e) {
            Log.e(TAG, "Catch a SQLiteException when query: ", e);
            checkSQLiteException(context, e);
            return null; 
        } 
    } 
 
    public static boolean requery(Context context, Cursor cursor) {
        try { 
            return cursor.requery();
        } catch (SQLiteException e) {
            Log.e(TAG, "Catch a SQLiteException when requery: ", e);
            checkSQLiteException(context, e);
            return false; 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:query
		return v;
	} 
 
	private void setupFeed() { 
		Uri feedUri = FeedProvider.FEEDS_URI.buildUpon().appendPath(feedId).build();
		feedCursor = contentResolver.query(feedUri, null, null, null, null);
		feedCursor.moveToFirst();
		feed = Feed.fromCursor(feedCursor);
	} 
 
	@Override 
	public Loader<Cursor> onCreateLoader(int loaderId, Bundle bundle) {
		Uri uri = FeedProvider.FEED_STORIES_URI.buildUpon().appendPath(feedId).build();
		CursorLoader cursorLoader = new CursorLoader(getActivity(), uri, null, FeedProvider.getStorySelectionFromState(currentState), null, DatabaseConstants.STORY_DATE + " DESC");
		return cursorLoader;
	} 
 
	@Override 
	public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
		if (cursor != null) {
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:query
			Uri contactUri) {
		ContactInfo contactInfo = new ContactInfo();
		long contactId = -1;
 
		// Load the display name for the specified person 
		Cursor cursor = contentResolver.query(contactUri,
				new String[] {
						Contacts._ID, Contacts.DISPLAY_NAME
				}, null, null, null); 
		try { 
			if (cursor.moveToFirst()) {
				contactId = cursor.getLong(0);
				contactInfo.setDisplayName(cursor.getString(1));
			} 
		} finally { 
			cursor.close();
		} 
 
		// Load the phone number (if any). 
		cursor = contentResolver.query(Phone.CONTENT_URI,

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:query
        Uri uri = createTaskEvent(task, cr, cv, false);
        task.setValue(Task.CALENDAR_URI, uri.toString());
    } 
 
    private static String getCalendarId(Uri uri, ContentResolver cr) {
        Cursor calendar = cr.query(uri, new String[] { CALENDAR_ID_COLUMN }, null, null, null);
        try { 
            calendar.moveToFirst();
            return calendar.getString(0);
        } catch (CursorIndexOutOfBoundsException e) {
            return null; 
        } finally  { 
            calendar.close();
        } 
    } 
 
    @SuppressWarnings("nls") 
    public static boolean deleteTaskEvent(Task task) {
        boolean eventDeleted = false;
        String uri;
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:query
     * Retrieves the contact information. 
     */ 
    @Override 
    public ContactInfo loadContact(ContentResolver contentResolver, Uri contactUri) {
        ContactInfo contactInfo = new ContactInfo();
        Cursor cursor = contentResolver.query(contactUri,
                new String[]{People.DISPLAY_NAME}, null, null, null);
        try { 
            if (cursor.moveToFirst()) {
                contactInfo.setDisplayName(cursor.getString(0));
            } 
        } finally { 
            cursor.close();
        } 
 
        Uri phoneUri = Uri.withAppendedPath(contactUri, Phones.CONTENT_DIRECTORY);
        cursor = contentResolver.query(phoneUri,
                new String[]{Phones.NUMBER}, null, null, Phones.ISPRIMARY + " DESC");
 
        try { 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:query, toString
        return Intent.createChooser(intent, "Select picture");
    } 
 
    public static String getLocalMediaPath(final Context context, final Intent intent) {
        final Uri uri = intent.getData();
        final Cursor cursor = context.getContentResolver().query(uri,
                new String[]{MediaStore.MediaColumns.DATA}, null, null, null);
 
        if (cursor == null) {
            throw new RuntimeException(String.format("Could not resolve file name for url: {0}",
                    uri.toString()));
        } 
 
        cursor.moveToFirst();
 
        final String ret = cursor.getString(0);
 
        cursor.close();
 
        return ret;
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:query, getPath
     * @param context 
     * @param contentURI 
     * @return 
     */ 
    public static String getRealPathFromURI(Context context, Uri contentURI) {
        Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null);
        if (cursor == null) { // Source is Dropbox or other similar local file path
            return contentURI.getPath();
        } else { 
            cursor.moveToFirst();
            int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
            return cursor.getString(idx);
        } 
    } 
 
    /** 
     * Returns the upper power-of-two 
     * @param v 
     * @return 
     */ 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related ContentResolver query Questions & Answers:

query Method Overview
Query the given URI, returning a Cursor over the result set.
See Code Examples for other Android ContentResolver Methods: