title: how can save images larger than 1MB on sqlite database android?
body: <p>I'm trying to build a notebook app using the SQLite database. everything works ok but whenever the images larger than 1MB Is added to the row of the database there won't be any new row shown on the recyclerView. while i delete all the items of the database it will work again correctly.</p>
  <p>the question is how can i save images larger than 1MB in my database?</p>
  <p><strong>this is the main database:</strong></p>
  <pre><code>public class MainDatabase extends SQLiteOpenHelper {
  private Context context;
  private SQLiteDatabase sqLiteDatabase;
  private static final String DATABASE_NAME = &quot;MainDatabase.db&quot;;
  private static final int DATABASE_VERSION = 1;
  
  /// memo library
  private static final String TABLE_NAME_MEMO = &quot;memo_library&quot;;
  private static final String MEMO_ID = &quot;memo_id&quot;;
  private static final String MEMO_TITLE = &quot;memo_title&quot;;
  private static final String MEMO_MEMO = &quot;memo_memo&quot;;
  private static final String MEMO_DATE = &quot;memo_date&quot;;
  private static final String MEMO_IMAGE = &quot;memo_image&quot;;
  private static final String MEMO_LOCATION = &quot;memo_location&quot;;
  
  /// tasks library
  
  public MainDatabase(@Nullable Context context) {
      super(context, DATABASE_NAME, null, DATABASE_VERSION);
      this.context = context;
  }
  
  @Override
  public void onCreate(SQLiteDatabase sqLiteDatabase) {
      try {
          String memo_query = &quot;CREATE TABLE &quot; + TABLE_NAME_MEMO +
                  &quot; (&quot; + MEMO_ID + &quot; INTEGER PRIMARY KEY AUTOINCREMENT, &quot; +
                  MEMO_TITLE + &quot; VARCHAR, &quot; +
                  MEMO_MEMO + &quot; TEXT, &quot; +
                  MEMO_DATE + &quot; VARCHAR, &quot; +
                  MEMO_IMAGE + &quot; BLOB NOT NULL, &quot; +
                  MEMO_LOCATION + &quot; VARCHAR);&quot;;
          sqLiteDatabase.execSQL(memo_query);
  
      } catch (Exception e) {
          Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  <p><strong>this is the method to insert the data:</strong></p>
  <p>// add data method:</p>
  <pre><code>void addMemo(MemoData memoData) {
      try {
          SQLiteDatabase db = this.getWritableDatabase();
  
          ContentValues contentValues = new ContentValues();
  
          contentValues.put(MEMO_TITLE, memoData.getTitle());
          contentValues.put(MEMO_MEMO, memoData.getMemo());
          contentValues.put(MEMO_DATE, memoData.getDate());
          contentValues.put(MEMO_IMAGE, convertImage(memoData));
          contentValues.put(MEMO_LOCATION, memoData.getLocation());
  
          long result = db.insert(TABLE_NAME_MEMO, null, contentValues);
          if (result == -1) {
              Toast.makeText(context, &quot;Failed to save&quot;, Toast.LENGTH_SHORT).show();
          } else {
              Toast.makeText(context, &quot;Successfully Saved&quot;, Toast.LENGTH_SHORT).show();
          }
      } catch (Exception e) {
          Toast.makeText(context, &quot;Memo Exception:  &quot; + e.getMessage(), Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  <p><strong>this is the part of the code that i wrote to add the image through its path:</strong></p>
  <pre><code> private byte[] convertImage(MemoData memoData) {
      Bitmap bitmap = null;
      ByteArrayOutputStream stream = null;
  
      if (memoData.getImage() != null){ // memoData is a class which i put the path of the image as String object in it
      Uri uri = Uri.parse(memoData.getImage());
  
          try {
              InputStream inputStream = context.getContentResolver().openInputStream(uri);
              bitmap = BitmapFactory.decodeStream(inputStream);
  
  
  
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }
      }else {
          bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.header1);
      }
  
  
      stream = new ByteArrayOutputStream();
      assert bitmap != null;
      bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  
      //assert stream != null;
      return stream.toByteArray();
     //return new byte[0];
  }
  </code></pre>