okareshaba / openintents

Automatically exported from code.google.com/p/openintents
0 stars 0 forks source link

OI File Manager: Result from querying OpenableColumns are pretty useless #324

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Reported by Belse in http://www.openintents.org/en/node/830 :

I start OI Filemanager with the following:

Intent i = new Intent( Intent.ACTION_GET_CONTENT );
i.addCategory( Intent.CATEGORY_OPENABLE );
i.setType( "*/*" );
startActivityForResult( Intent.createChooser( i, null ), RequestCodes.Blabla);

and get the following intent in response
{ act=android.intent.action.VIEW 
dat=content://org.openintents.filemanager/mimetype//mnt/sdcard/gz_full }

When I try to query the contentResolver (with uri = 
"content://org.openintents.filemanager/mimetype//mnt/sdcard/gz_full", I get 
pretty useless info.

cursor = contentResolver.query( uri, new String[]{ 
OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE }, null, null, null );
if ( cursor != null && cursor.moveToFirst() )
{
name = cursor.getString( 0 ); // Returns "/mnt/sdcard/gz_full", expecting 
"gz_full" (last segment)
size = cursor.getLong( 1 ); // Returns 0, expecting file-size... or null if 
it's unknown
}
else
{
// stuff
}

See 
http://developer.android.com/reference/android/content/Intent.html#CATEGORY_OPEN
ABLE
and http://developer.android.com/reference/android/provider/OpenableColumns.html

Original issue reported on code.google.com by peli0...@googlemail.com on 16 Feb 2011 at 6:54

GoogleCodeExporter commented 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

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r3267.

Original comment by peli0...@googlemail.com on 27 Mar 2011 at 2:26