Give Permission in manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
File destination = new File(Environment.getExternalStorageDirectory(),"image.jpg");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(destination));
startActivityForResult(intent, CAMERA_PICTURE);
then override onActivityResult gat image file from destination image it convert into bitmap and save this.
then convert it into byte array
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == CAMERA_PICTURE && resultCode == Activity.RESULT_OK) {
realImageStr = new String("");
try {
FileInputStream in = new FileInputStream(destination);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 10; //Downsample 10x
Log.d("PP", " bitmap factory=========="+options);
Bitmap user_picture_bmp = BitmapFactory.decodeStream(in, null, options);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
user_picture_bmp.compress(Bitmap.CompressFormat.PNG, 100, bos);
byte[] bArray = bos.toByteArray();
} catch (Exception e)
{
} }}
When you will save into byte type then save in to database ur byteCode in image coloumn and image column data type is BLOB type.