I\'m querying the CallLog content provider and need to detect the column types.
In Honeycomb and newer (API Level 11+) you can get a columns preferred data type by c
You can use this code when cursor is positioned in a valid row:
CursorWrapper cw = (CursorWrapper)cursor;
Class> cursorWrapper = CursorWrapper.class;
Field mCursor = cursorWrapper.getDeclaredField("mCursor");
mCursor.setAccessible(true);
AbstractWindowedCursor abstractWindowedCursor = (AbstractWindowedCursor)mCursor.get(cw);
CursorWindow cursorWindow = abstractWindowedCursor.getWindow();
int pos = abstractWindowedCursor.getPosition();
for ( int i = 0; i < cursor.getColumnCount(); i++ ) {
String type = null;
if (cursorWindow.isNull(pos, i)) {
type = "Cursor.FIELD_TYPE_NULL";
} else if (cursorWindow.isLong(pos, i)) {
type = "Cursor.FIELD_TYPE_INTEGER";
} else if (cursorWindow.isFloat(pos, i)) {
type = "Cursor.FIELD_TYPE_FLOAT";
} else if (cursorWindow.isString(pos, i)) {
type = "Cursor.FIELD_TYPE_STRING";
} else if (cursorWindow.isBlob(pos, i)) {
type = "Cursor.FIELD_TYPE_BLOB";
}
}
Note that Cursor.FIELD_TYPE_* constant values are defined starting from HONEYCOMB.