Code example for ContentResolver

Methods: insertquery

0
        double longitude = 0f;
 
        ContentResolver contentResolver = context.getContentResolver();
        Cursor cursor = null;
        try { 
            cursor = contentResolver.query(sourceUri, IMAGE_PROJECTION, null, null, null);
            if ((cursor != null) && cursor.moveToNext()) {
                dateTaken = cursor.getLong(INDEX_DATE_TAKEN);
                latitude = cursor.getDouble(INDEX_LATITUDE);
                longitude = cursor.getDouble(INDEX_LONGITUDE);
            } 
        } catch (Exception e) {
            // Ignore error for lacking property columns from the source. 
        } finally { 
            if (cursor != null) {
                cursor.close();
            } 
        } 
 
        ContentValues values = new ContentValues();
        values.put(Images.Media.TITLE, saveFileName);
        values.put(Images.Media.DISPLAY_NAME, file.getName());
        values.put(Images.Media.MIME_TYPE, "image/jpeg");
        values.put(Images.Media.DATE_TAKEN, dateTaken);
        values.put(Images.Media.DATE_MODIFIED, now);
        values.put(Images.Media.DATE_ADDED, now);
        values.put(Images.Media.ORIENTATION, 0);
        values.put(Images.Media.DATA, file.getAbsolutePath());
        values.put(Images.Media.SIZE, file.length());
 
        // TODO: Change || to && after the default location issue is fixed. 
        if ((latitude != 0f) || (longitude != 0f)) {
            values.put(Images.Media.LATITUDE, latitude);
            values.put(Images.Media.LONGITUDE, longitude);
        } 
        return contentResolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values);
    } 
} 
Connect your IDE to all the code out there  Get Codota for Java