*
* @return highest image id in database or -1 if conditions fail
*/
public int getId() {
String[] columns = new String[]{Media._ID, Media.ORIENTATION};
Cursor cursor = application.managedQuery( Media.EXTERNAL_CONTENT_URI, columns, null, null, Media._ID + " DESC" );
// check if table has any rows at all
if( !cursor.moveToFirst() ) {
return -1;
}
// get latest id from db and stored id in application
latestId = cursor.getInt( cursor.getColumnIndex( Media._ID ) );
int maxId = application.getMaxId();
// if id from db is equal or lower to stored id it means user changed or
// deleted somewhere in table so store the new highest id and return
if( latestId <= maxId ) {
application.setMaxId( latestId );
return -1;
}
// If orientation is null it means new image is not a photo but we will
// store highest id and return
String orientation = cursor.getString( cursor.getColumnIndex( Media.ORIENTATION ) );
if( orientation == null ) {
application.setMaxId( latestId );
return -1;
}