I'm trying to insert image to sqlite table.currently i have insert text value to sqlite i want to insert both text value and image to sqlite table.my app can capture image from camera and it's display in Imageview.when submit button click i want to insert that image to sqlite table.this is my code.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBut.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
submitData();
}
});
}
Show captured image
private void showPhoto(String photoUri) {
File imageFile = new File (photoUri);
if (imageFile.exists()){
Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
BitmapDrawable drawable = new BitmapDrawable(this.getResources(), bitmap);
mCapturedImage.setScaleType(ImageView.ScaleType.FIT_CENTER);
mCapturedImage.setImageDrawable(drawable);
}
}
private void submitData()
{
try {
String VndCode=mValu.getText().toString();
insertLC(VndCode);
DbBackup.copyDatabase(getApplicationContext());
} catch (Exception e) {
// TODO: handle exception
}
}
public void insertLC(String vendorcode) {
// TODO Auto-generated method stub
mDbA= new DBAdapter(this);
mDbA.open();
try {
long i = mDbA.insertLC(vendorcode);
if(i != -1){
Toast.makeText(MainActivity.this, "Data Recorded",Toast.LENGTH_LONG).show();
}
} catch (SQLException e) {
Toast.makeText(MainActivity.this, "Some problem occurred",
Toast.LENGTH_LONG).show();
}
mDbA.close();
}
DBA Adapter
private static final String VALUE_TABLE = "tracked_value";
public static final String VAL_ID = "fa_id";
public static final String VALUE= "t_value";
public long insertLC(String t_value)
{
ContentValues initialValues = new ContentValues();
initialValues.put(VALUE, t_value);
return mDb.insert(VALUE_TABLE, null, initialValues);
}
DB Helper
public class DBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "NEW.db";
private static final int DATABASE_VERSION = 1;
private static final String VALUE_TABLE = "tracked_value";
public static final String VAL_ID = "fa_id";
public static final String VALUE= "t_value";
private static final String CREATE_VALUE_TABLE = "CREATE TABLE "+VALUE_TABLE+" ("+VAL_ID+" integer primary key autoincrement,"+VALUE+" varchar);";
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_VALUE_TABLE);
}
}
i already have insert text value to table.but i don't know how to insert image to sqlite table.