Closed GoogleCodeExporter closed 9 years ago
More comments from Belse at http://www.openintents.org/en/node/830 :
---------------
Make sure you consider the projection part, without adding, removing or rearranging the provided data... if possible. I'm not sure how you translate selection and sortOrder for a single file... maybe it's relevant for getting files inside a folder.
A simple solution should be:
public Cursor query(Uri uri, String[] projection, String selection, String[]
selectionArgs, String sortOrder)
{
if( projection == null || projection.length == 0 )
{
// Create default projection with all supported columns (not sure if _data
should be here, since it should not be used by clients
projection = new String[]
{
BaseColumns._ID, // "_id"
MediaStore.MediaColumns.DISPLAY_NAME, // "_display_name"
MediaStore.MediaColumns.SIZE, // "_size"
MediaStore.MediaColumns.DATA, // "_data", might not be presented to the user
MediaStore.MediaColumns.MIME_TYPE // "mime_type"
};
}
else
{
// Check for non-supported columns and null columns?
// Unsupported rows should be a client error :)
}
MatrixCursor cursor = new MatrixCursor( projection );
MatrixCursor.RowBuilder row = cursor.newRow();
String col;
for( int i = 0; i < projection.length; i++ )
{
col = projection[i];
if( col.equals( BaseColumns._ID ) )
{
row.add( 0L ); // unique id for file?
}
else if( col.equals( MediaStore.MediaColumns.DISPLAY_NAME ) )
{
row.add( file.getName() );
}
else if( col.equals( MediaStore.MediaColumns.SIZE ) )
{
row.add( file.length() );
}
// etc...
}
return cursor;
}
Note that:
Image.Media is a subclass of MediaStore.MediaColumns
MediaStore.MediaColumns.DISPLAY_NAME = OpenableColumns.DISPLAY_NAME
MediaStore.MediaColumns.SIZE = OpenableColumns.SIZE
And as MediaColumns is better documented, size is of type "INTEGER (long)"
Original comment by peli0...@googlemail.com
on 17 Feb 2011 at 12:43
This issue was closed by revision r3267.
Original comment by peli0...@googlemail.com
on 27 Mar 2011 at 2:26
Original issue reported on code.google.com by
peli0...@googlemail.com
on 16 Feb 2011 at 6:54