从两个不同的数据源中选择排序数据

时间:2011-12-06 13:54:32

标签: java android cursor

我需要最新的图片,我需要从两个不同的地方选择。我该怎么做?

以下是我的代码,它只能从/dcim/camera返回,而不是从eye-fi返回时它应该能够从两者返回。

private void PopulateDataSource() {
    if (_context == null) return;

    if(_context.getContentResolver() != null) {
        final ContentResolver cr = _context.getContentResolver();

    String[] projections = new String[] {
        MediaStore.Images.ImageColumns._ID,
        MediaStore.Images.ImageColumns.DATE_TAKEN,
        MediaStore.Images.ImageColumns.DATA };
        String sortOrder = String.format(
            "%s limit 10", Images.ImageColumns.DATE_TAKEN + " DESC"); 

    final String[] selectionArgs = { 
        getBucketId(Environment.getExternalStorageDirectory().toString() +
        "/Eye-Fi"),
        getBucketId(Environment.getExternalStorageDirectory().toString() +
        "/DCIM/Camera") };

    final String selection = MediaStore.Images.Media.BUCKET_ID + " = ?";

    try {
        // select all images from DataBase and set it in Cursor
        SearchCursor = cr.query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projections, selection, selectionArgs, sortOrder);

        } 
        catch (Exception ex) {
            Log.e("Cursor failed", ex.getMessage());
        }       
    }
}

1 个答案:

答案 0 :(得分:0)

用以下内容替换您的选择字符串:

final String selection = MediaStore.Images.Media.BUCKET_ID + " IN (?, ?)";