Skip to content Skip to sidebar Skip to footer

How To Save And Retrieve Path Image In Sqlite Android

i want to save and retrieve image path in my application this is my DBhelper public void insert(String kdstore,String nama, String alamat, String kodepos, String notel, St

Solution 1:

You can use onActivityResult for saving path after capturing photo.

@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stubsuper.onActivityResult(requestCode, resultCode, data);
    if( requestCode == IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) {
        DBHelperdbHelper=newDBHelper(this);
        SQLiteDatabasesql= dbHelper.getWritableDatabase();
        sql.execSQL("insert statement for inserting path to database");
        sql.close();
        dbHelper.close();
    }
}

Solution 2:

Use this code for getting the image path...

publicvoidonActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
        case SELECT_IMAGE:
            StringimagePath= getPath(data.getData());
            Savingimagepath(imagePath);
            img.setImageDrawable(Drawable.createFromPath(imagePath));
            break;
        }
    }
}

and this is the sample method for saving the path in database

privatevoidSavingimagepath(String imagePath) {
    testDatabase testDB = new testDatabase(contact.this);
    testDB.open();

    try {
        testDB.getexecute("delete from ctoffice");
        testDB.getexecute("insert into ctoffice (idnt1)Values('"
                + imagePath + "')");
    } catch (Exception e) {
        System.out.println(e);
    }
    testDB.close();
}

Post a Comment for "How To Save And Retrieve Path Image In Sqlite Android"