I am trying save a Bitmat from a ImageView on database sqlite but I can't do.
I save Strings but I dont know Images.
My code
BBDD class
public class BBDD extends SQLiteOpenHelper
{
String create = "CREATE TABLE info(usuario TEXT, " +
"ma TEXT, " +
"ti TEXT, " +
"loc TEXT, " +
"lati TEXT, " +
"longi TEXT, " +
"obs TEXT," +
"date TEXT, " +
"time TEXT, " +
"in TEXT, " +
"imgone BLOB, " +
"imgtwo BLOB, " +
"imgthree BLOB, " +
"imgfour BLOB) ";
public BBDD (Context contexto, String nombre, CursorFactory factory,
int version)
{
super(contexto, nombre, factory, version);
}
public void onCreate (SQLiteDatabase db)
{
db.execSQL(create);
}
public void onUpgrade (SQLiteDatabase db, int versionAnt, int versionNue)
{
db.execSQL(create);
}
}
activity
//******//
//declares
public BBDD info;
//******//
//onClick button to save
public void send (View view)
{
usuario = "ful";
ma = tv_ma.getText().toString();
ti = "T";
loc = tv_lug.getText().toString();
lati = tv_latib.getText().toString();
longi = tv_longb.getText().toString();
obs = txtStatus.getText().toString();
SimpleDateFormat dfDate = new SimpleDateFormat("dd-MMM-yyyy");
String data="";
Calendar c = Calendar.getInstance();
data=dfDate.format(c.getTime());
date = data;
SimpleDateFormat dfDate2 = new SimpleDateFormat("HH:mm:ss");
String data2="";
Calendar c2 = Calendar.getInstance();
data2=dfDate2.format(c2.getTime());
time = data2;
in = tv_infraccionb.getText().toString();
info = new BBDD(this, "BBDD", null, 1);
SQLiteDatabase db = info.getWritableDatabase();
//*****//
//validate empty variables
//*****//
if (db != null) {
ContentValues reg = new ContentValues();
reg.put("usuario", usuario);
reg.put("ma", ma);
reg.put("ti", ti);
reg.put("loc", loc);
reg.put("lati", lati);
reg.put("longi", longi);
reg.put("obs", obs);
reg.put("date", date);
reg.put("time", time);
reg.put("in", in);
My problem here, I dont know how I can save Images on "reg.put..."
if (db.insert("info", null, reg) != -1) {
Toast.makeText(this, "Reg insert", Toast.LENGTH_LONG)
.show();
db.close();
}
} else {
Toast.makeText(this, "Error", Toast.LENGTH_LONG)
.show();
}
}
}
I get the image of bundle Bitmap format
Bundle extras = getIntent().getExtras();
byte[] food = extras.getByteArray("picture");
Bitmap fo = BitmapFactory.decodeByteArray(food, 0, food.length);
img_ImageView.setImageBitmap(fo);
any suggestions?
Aucun commentaire:
Enregistrer un commentaire