Skip to content Skip to sidebar Skip to footer

Storing And Retrieving Uri From Sqlite

I’m a newbie developer and I am currently working on an app in which part of the functionality allows users to capture an image, store it in the app’s file system, and store it

Solution 1:

In my application I want to store profile picture of user in SQLite database So I have added one String Column for Storing Path of Image,image will be selected from Gallery

//Executed When user Click on image for selecting profile from GalleryImageViewprofileperson= (ImageView) findViewById(R.id.profileperson);
    profileperson.setOnClickListener(newView.OnClickListener() {
        @OverridepublicvoidonClick(View v) {
            Intenti=newIntent(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, 1);
        }
    });

String path;
@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1 && resultCode == RESULT_OK && null != data) {
        UriselectedImage= data.getData();
        String[] fillPath = {MediaStore.Images.Media.DATA};
        Cursorcursor= getContentResolver().query(selectedImage, fillPath, null, null, null);
        assert cursor != null;
        cursor.moveToFirst();
        path = cursor.getString(cursor.getColumnIndex(fillPath[0]));
        cursor.close();
        profileperson.setImageBitmap(BitmapFactory.decodeFile(path));
    }
}

Then in for displaying I have fetch path of image using Cursor

String employeeimage;
...
employeeimage = cursor.getString(cursor.getColumnIndex("employeeimage"));  //employeeimage is column name

Now I have display all data in RecyclerView so I have use Adapter for binding data.

List<Data> list = Collections.emptyList();
...
    @Override
publicvoidonBindViewHolder(final ViewHolder holder, final int position) {

    /*
    * get items from list of particular position and set into respective textview
    * */

    String path=list.get(position).employeeImage;

    Picasso.with(context).load(new File(path)).into(holder.imageViewPerson);
}

Post a Comment for "Storing And Retrieving Uri From Sqlite"