Looking for some help. I am trying to add strings of information to a sqlite database which is working OK. But now I want to add an image captured from the camera. I have setup the DB with a new blob entry. Thing I cant understand is passing the byte image from the oncallistener of "add photo" to the oncallistener of the "Add to DB" button. The add DB button is where I write to the database.
Any ideas?
add_save_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
add_db_bsdate = add_bsdate.getText().toString();
add_db_report = add_report.getText().toString();
add_db_longt = add_longt.getText().toString();
add_db_lat = add_lat.getText().toString();
add_db_type = add_type.getSelectedItem().toString();
add_db_city = add_city.getSelectedItem().toString();
byte[] imageInByte = null;
dbHandler.Add_Blackspot(new Blackspot(add_db_bsdate, add_db_report, add_db_longt, add_db_lat, add_db_type, add_db_city, imageInByte)); //imageInByte declared from ActivityResult
Toast_msg = "Data inserted successfully";
Show_Toast(Toast_msg);
Reset_Text();
//}
}
});
}
My ActivityResults that returns imageInByte. How do I write this to DB above?
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK)
return;
switch (requestCode) {
case CAMERA_REQUEST:
Bundle extras = data.getExtras();
if (extras != null) {
mImageView = (ImageView) findViewById(R.id.mImageView);
//Bitmap imageBitmap = (Bitmap) extras.get("data");
Bitmap yourImage = extras.getParcelable("data");
// convert bitmap to byte
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yourImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte imageInByte[] = stream.toByteArray();
mImageView.setImageBitmap(yourImage);
// Inserting Contacts
//dbHandler.Add_Blackspot(new Blackspot(add_db_bsdate, add_db_report, add_db_longt, add_db_lat, add_db_type, add_db_city));
//dbHandler.Add_Blackspot(new Blackspot("Android", imageInByte));
//Intent i = new Intent(Add_Update_User.this,
//Add_Update_User.class);
//startActivity(i);
//finish();
//callCamera();
}
break;