Click here to Skip to main content
15,902,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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! :(

Java
// Button Click saves image to sqlite

  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();

        }
    });

// Database Handler:

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

Java
public void onActivityResult(int reqCode,int resCode,Intent data){

    if(resCode==RESULT_OK){
        if(reqCode==1){
            ImageUri = data.getData();
            profileIV.setImageURI(data.getData());
        }


    }
Posted
Updated 11-Nov-15 21:29pm
v2
Comments
Richard MacCutchan 12-Nov-15 3:30am    
You are not uploading an image anywhere in this code, just a URI.
Afzaal Ahmad Zeeshan 12-Nov-15 4:53am    
Apart from what Richard said, Why do you want to do that? Do not fill in the databases with binary data of images. Store images on file system, keep their names in the database.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900