Save image path name from sdcard to Sqlite database
am having a little trouble here. i am trying to store and retrieve images from an sqlitedatabase by storing their image path name. the images are stored in the sdcard. I tried this code, but its not working.
saving image path:
String filename = "/sdcard/barn.jpg"
ContentValues vals2 = new ContentValues(); //create content values and store it.
vals.put(ImageDB.SHOW, filename);
imagedb.tagImage(vals2);
public long tagImage(ContentValues val){
Log.d(TAG,"tagged Images");
return db.insert(DATABASE_TABLE, null, val);
}
retrieving :
Cursor cursor = imagedb.retrieveTag(tag);
/*method for retrieving*/
public Cursor retrieveTag(String tag){
Stri开发者_C百科ng[] condition = {tag)};
Cursor cursor = db.query(DATABASE_TABLE, condition, null, null, null, null, null);
cursor.moveToNext();
return cursor;
}
The cursor is not returning anything and i sometimes get a CursorIndexOutofBoundsException. Is this a correct way to save and retrieve from an sqlitedatabase or does the filename pose a problem for the sqlite database?.. How can i store it correctly?.. Thank you.
Try getting the root directory with Environment.getExternalStorageDirectory(), harcoding "/sdcard/" may not work.
精彩评论