I have a custom content provider for sharing files. For columns (via query method) i support only OpenableColumns.DISPLAY_NAME
and OpenableColumns.SIZE
.
While testing i noticed that Photos app (Google+) have problems (NullPointerException) opening images through my content provider, because they are retrieving _data column, which is not supported in my content provider, and for it i return null (for column names and values).
Later i updated this part of code, so now it returns in columns array _data column, but it's value as null.
It seems that this works now ok in Photos app, but i'm curious... Does anybody know if this is in general specified/standardized, what we should return in case of unsupported column?
Part of confusion is: should we on side of content provider handle such scenarios as i did, or should apps that uses content providers do additional checking? Since some apps can check if column exists, then do something with value (but value will be null). On other side, other apps can expect column, and assume if column exists, then value should also exists.
I know that the best approach is to cover all situations, but initial question remains: is such handling specified somewhere in the documentation?
Here is also section of code for better imagination:
String cols[] = new String[projection.length];
Object vals[] = new Object[projection.length];
for(int i=0; i<projection.length; i++){
//projection is passed to query() by 3rd party app
String column = projection[i];
if ( OpenableColumns.DISPLAY_NAME.equals(column) ) {
cols[i] = OpenableColumns.DISPLAY_NAME;
vals[i] = name;
}else if ( OpenableColumns.SIZE.equals(column) ) {
cols[i] = OpenableColumns.SIZE;
vals[i] = file.length();
}else{
//THIS PART OF CODE WAS LATER ADDED
//for unsupported column return column name
//but it's value will be null
cols[i] = column;
vals[i] = null;
}
}
MatrixCursor mc = new MatrixCursor(cols, 1);
mc.addRow(vals);