So for my android application i can successfully insert an image to sqlite as a string. But im not sure exactly how i can retrieve this image from the database and convert it to a Image and display it in my app. Stuck for weeks, help appreciated! :(
upload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Student student = new Student(profadmin.getText().toString());
student.setImageUri(ImageUri);
stud.updateImage(student);
Toast passes = Toast.makeText(ProfileActivity.this, "Profile Picture has been updated", Toast.LENGTH_SHORT);
passes.show();
}
});
public int updateImage(Student student) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(STUDENT_IMAGEURI, student.getImageUri().toString());
int rowsAffected = db.update(STUDENT_TABLE, values, STUDENT_ADMINNO + "=?", new String[]{String.valueOf(student.getAdminNo())});
db.close();
return rowsAffected;
}
Edit: Uploaded the image by clicking the empty ImageView (profileIV) , opening the android emulator gallery, choose image and then image will be displayed on the app. Then i click the 'Upload' button and it sends it to the database and uploads
public void onActivityResult(int reqCode,int resCode,Intent data){
if(resCode==RESULT_OK){
if(reqCode==1){
ImageUri = data.getData();
profileIV.setImageURI(data.getData());
}
}