Ad

How To Update Profile Image To Firebase After Select Picture And Crop It?

How can I update my current user profile picture into firebase after I select an image and crop it?

Here is my code:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE && resultCode == RESULT_OK){
        Uri imageUri = CropImage.getPickImageResultUri(getActivity(),data);
        cropRequest(imageUri);

    }
    if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE){
        CropImage.ActivityResult result = CropImage.getActivityResult(data);
        if (resultCode == RESULT_OK){
            try {
                Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), result.getUri());
                imgUserProfile.setImageBitmap(bitmap);

                final ProgressDialog pd = new ProgressDialog(getContext());
                pd.setMessage("Please wait ");
                pd.show();
            } catch (IOException e){
                e.printStackTrace();
            }
        }
    }
}

How do I continue from there? Any suggestions?

Ad

Answer

There are many options:

  1. One of the most useful ones I would use would be to upload the picture to Firebase Storage. It's really easy to upload it, and whenever your user signs in again you could download the file to local storage for daily usage.
  2. Another option(this is a bit clunky) might be to store the pixel array of the bitmap in a firebase node. It is blazingly fast and you can store it in your firebase database, but also in your shared preferences. By using an additional compression function you could even enhance the function.

I would recommend, however, using firebase storage as it is the one and only secure option. So go for it. For firebase storage take a look at this link it's the documentation(pretty easy to follow):

https://firebase.google.com/docs/storage/android/upload-files

And also here: https://code.tutsplus.com/tutorials/image-upload-to-firebase-in-android-application--cms-29934

Ad
source: stackoverflow.com
Ad