D
D
DeNissss44442020-11-21 22:18:55
Android
DeNissss4444, 2020-11-21 22:18:55

Why is the firebase photo not being added and displayed in CircleImageView?

There is a user settings activation, it has a CircleImageView, where the user should insert his photo and it should add to the firebase. I looked at various examples of how to do this, I understood the principle, but no matter how I tried, the firebase photo is not added and is not displayed in the CircleImageView . Please help me understand what is wrong.
Here are my permissions in Manifest

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNETer"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

Here is the activation of the settings itself
public class SettingsActivity extends AppCompatActivity {
private CircleImageView image_settings;
    private EditText login_settings;
    private EditText about_settings;
    private Button save_settings_btn;

     private FirebaseAuth mAuth;
     private DatabaseReference rootReference;
     private String currentUserID;
     private final static int GALLERY_PICK = 1;

     private FirebaseStorage storage;
     private StorageReference imgProfileBD;
     private Uri filePath;
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        storage = FirebaseStorage.getInstance();
        imgProfileBD = storage.getReference();
      
        mAuth = FirebaseAuth.getInstance();
        currentUserID = mAuth.getCurrentUser().getUid();
        rootReference = FirebaseDatabase.getInstance().getReference();

        image_settings = (CircleImageView) findViewById(R.id.profile_image);
        login_settings = (EditText) findViewById(R.id.setUserName);
        about_settings = (EditText) findViewById(R.id.setAbout);
        save_settings_btn = (Button) findViewById(R.id.saveSettings);

        image_settings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                chooseImg ();
                uploadImage();
            }
        });

        save_settings_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UpdateInf();
            }
        });
    }
 private void chooseImg (){
        Intent galleryIntent = new Intent();
        galleryIntent.setType("image/*");
        galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(galleryIntent, GALLERY_PICK);
    }
    @Override
     protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
         if(requestCode == GALLERY_PICK && requestCode == RESULT_OK && data != null && data.getData() != null){
             filePath = data.getData();
             try {
                 Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
                 image_settings.setImageBitmap(bitmap);
             } catch (IOException e) {
                 e.printStackTrace();
             }
         }
     }
  private void uploadImage(){
        if(filePath != null){
            final ProgressDialog progressDialog = new ProgressDialog(this);
            progressDialog.setTitle("Uploading...");
            progressDialog.show();

            StorageReference ref = imgProfileBD.child("ImageProfile/"+ UUID.randomUUID().toString());
            ref.putFile(filePath)
                    .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    progressDialog.dismiss();
                    Toast.makeText(SettingsActivity.this, "Uploaded", Toast.LENGTH_SHORT).show();
                }
            })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            progressDialog.dismiss();
                            Toast.makeText(SettingsActivity.this, "Failed "+e.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    })
                    .addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
                        @Override
                        public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                            double progress = (100.0*taskSnapshot.getBytesTransferred()/taskSnapshot
                                    .getTotalByteCount());
                            progressDialog.setMessage("Uploaded "+(int)progress+"%");
                        }
                    });
        }
     }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question