Android ContentResolver - top ranked examples from Open Source projects

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

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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:insert, openAssetFileDescriptor, query, update
	public void updatePhoto(ContentResolver cr, byte[] photo, String id, boolean markDirty, boolean fromthumb) { 
		if (cr == null || id == null) {
			return; 
		} 
		 
		long rawId = queryForRawContactId(cr, Long.parseLong(id));
		if (rawId < 0) {
			return; 
		} 
		//if(!fromthumb) 
			writeDisplayPhoto(cr, rawId, photo);
		 
		if(photo == null)
		{ 
			id = String.valueOf(rawId);
			ContentValues values = new ContentValues(); 
			int photoRow = -1; 
			 
			// query for existing photo 
			String where = ContactsContract.Data.RAW_CONTACT_ID + " == " + 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:update, put
    @Override 
    protected void onHandleIntent(Intent intent) {
        String action = intent.getAction();
        if (ACTION_CLEAR_MISSED_CALLS.equals(action)) {
            // Clear the list of new missed calls. 
            ContentValues values = new ContentValues();
            values.put(Calls.NEW, 0);
            values.put(Calls.IS_READ, 1);
            StringBuilder where = new StringBuilder();
            where.append(Calls.NEW);
            where.append(" = 1 AND ");
            where.append(Calls.TYPE);
            where.append(" = ?");
            getContentResolver().update(Calls.CONTENT_URI, values, where.toString(),
                    new String[]{ Integer.toString(Calls.MISSED_TYPE) });
            mApp.notificationMgr.cancelMissedCallNotification();
        } else if (ACTION_CLEAR_BLACKLISTED_CALLS.equals(action)) {
            mApp.notificationMgr.cancelBlacklistedCallNotification();
        } 
    } 
7
CodeRank
Experience pair programming with AI  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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:notifyChange, getPathSegments
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        isValidUri(uri);
 
        SQLiteDatabase db = mBookOpenHelper.getWritableDatabase();
        // URIからテーブル名を取得 
        String tableName = uri.getPathSegments().get(0);
        int updatedCount = db.update(tableName, values, selection, selectionArgs);
        getContext().getContentResolver().notifyChange(uri, null);
        return updatedCount;
    } 
 
    // このContentProviderで使用可能なURIかを判定します。 
    // 使用不可の場合はIllegalArgumentExceptionを投げます。 
    private void isValidUri(Uri uri) {
        if (URI_MATCHER.match(uri) != Book.BOOK) {
            throw new IllegalArgumentException("Unknown URI : " + uri);
        } 
    } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:delete, insert, query
	 */ 
	public static long getPlaylist(ContentResolver resolver, String name)
	{ 
		long id = -1;
 
		Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
			new String[] { MediaStore.Audio.Playlists._ID },
			MediaStore.Audio.Playlists.NAME + "=?",
			new String[] { name }, null);
 
		if (cursor != null) {
			if (cursor.moveToNext())
				id = cursor.getLong(0);
			cursor.close();
		} 
 
		return id;
	} 
 
	/** 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:insert
    } 
 
    public static Uri insert(Context context, ContentResolver resolver,
            Uri uri, ContentValues values) {
        try { 
            return resolver.insert(uri, values);
        } catch (SQLiteException e) {
            Log.e(TAG, "Catch a SQLiteException when insert: ", e);
            checkSQLiteException(context, e);
            return null; 
        } 
    } 
} 
7
CodeRank
Experience pair programming with AI  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
Experience pair programming with AI  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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:query
    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}, 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,
                new String[]{Phone.NUMBER},
                Phone.CONTACT_ID + "=" + contactId, null, Phone.IS_SUPER_PRIMARY + " DESC");

7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android ContentResolver Questions & Answers:

Other Android ContentResolver Examples

68:	    values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/3gpp");
69:	    values.put(MediaStore.Audio.Media.DATA, audiofile.getAbsolutePath());
70:	    ContentResolver contentResolver = getContentResolver();
71:	
72:	    Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

Read More

See Code Examples for Android ContentResolver Methods: