I saved an image by converting it to a array of bytes , in a column in Sqlite with data type byte .
When I make a cursor to fetch this image from the bank using the Cursor class and the get_blob()
method, it says it can not convert.
What am I doing wrong?
public List<Locais> listaDeMemorias() {
DataBaseApp dtbApp = new DataBaseApp( this );
SQLiteDatabase dtb = dtbApp.getReadableDatabase();
try {
Cursor c = dtb.rawQuery("select idLocal,dsLocal,dtVisita,dsObservacoes,imagem from Locais", null);
Date data = new Date(System.currentTimeMillis());
while (c.moveToNext()) {
System.out.println("Tem dados");
int id = c.getInt( 0 );
System.out.println( "ID: " + id );
byte[] imgData = c.getBlob(4);
Bitmap img = BitmapFactory.decodeByteArray( imgData, 0, imgData.length);
Locais locais = new Locais(c.getInt(0),c.getString(1),new Timestamp( c.getLong( 2 )),c.getString(3),img);
System.out.println( "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" );
listaLocais.add(locais);
}
return listaLocais;
} catch ( Exception e ) {
System.out.println( e.getMessage() );
} finally {
dtb.close();
}
System.out.println( "Enviando lista de locais: " + listaLocais.size() );
return listaLocais;
}