title: How to save a photo in android database as a blob
body: <p>I'm trying to save a photo as a blob in the SQLite (not just reference it). mCurrentMediaPath is the current path where the photo will be stored. Now, I need to save it to the database after the picture is taken and save button pressed (I guess after the intent).</p>
  
  <pre><code>public Uri insert(byte[] image) {
      return getContentResolver().insert(MyContentProvider.CONTENT_URI7, createContentValues(image));
  }
  private ContentValues createContentValues(byte[] image) {
      ContentValues docsInsert = new ContentValues();
      docsInsert.put(Db.COLUMN_FILETYPE, "PHOTO");
      docsInsert.put(Db.COLUMN_NAME, mCurrentMediaPath);
      docsInsert.put(Db.COLUMN_FILE, image);
      return docsInsert;
  }
  // convert from bitmap to byte array
  public byte[] getBytesFromBitmap(Bitmap bitmap) {
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      bitmap.compress(CompressFormat.JPEG, 70, stream);
      return stream.toByteArray();
  }
  
  
  private void dispatchMediaIntent(int actionCode) {
      switch(actionCode) {
      case ACTION_TAKE_PHOTO:
          Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          File f = null;
          try {
              f = setUpPhotoFile(ACTION_TAKE_PHOTO);
              mCurrentMediaPath = f.getAbsolutePath();
              takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
          } catch (IOException e) {
              e.printStackTrace();
              f = null;
              mCurrentMediaPath = null;
          }
          startActivityForResult(takePictureIntent, actionCode);
          break;
      case ACTION_TAKE_VIDEO:
          Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
          startActivityForResult(takeVideoIntent, actionCode);
          break;
      default:
          break;          
      }       
  }
  </code></pre>
  
  <p>Where should I implement the insertion?</p>
  
  <pre><code>     //SAVING TO DATABASE
          BitmapFactory.Options bmOptions = new BitmapFactory.Options();
          bmOptions.inJustDecodeBounds = true;
          BitmapFactory.decodeFile(mCurrentMediaPath, bmOptions);
          Bitmap bitmap = BitmapFactory.decodeFile(mCurrentMediaPath, bmOptions);
  
          insert(getBytesFromBitmap(bitmap));
  </code></pre>