Exemplo n.º 1
0
  private boolean saveImageToDataBase(Bitmap bitmapImage, String fileName) {
    // this method is to save the photo and photo name into database return true if success return
    // false if fall.
    boolean flag = true;

    MyDataBase mdb = new MyDataBase(TakePicture.this, DB_NAME, null, DB_VERSION);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bitmapImage.compress(Bitmap.CompressFormat.JPEG, 100, bos);
    byte[] img = bos.toByteArray();
    SQLiteDatabase db = mdb.getWritableDatabase();
    try {

      ContentValues cv = new ContentValues();
      cv.put("IMAGES", img);
      cv.put("IMAGES_NAME", fileName);

      db.insert(TABLE_NAME, null, cv);
    } catch (Exception e) {
      flag = false;
    } finally {
      db.close();
    }

    return flag;
  }
Exemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cursor_list_view);

    // find ListView
    ListView list = (ListView) findViewById(R.id.CountryList);

    // DataBase
    MyDataBase database = new MyDataBase(this);

    // create adapter
    CountryCursorAdapter adapter = new CountryCursorAdapter(this, database.getCountryCursor());

    // assign adapter to ListView
    list.setAdapter(adapter);
  }