Есть активити настроек пользователя, в нем есть CircleImageView, куда пользователь должен вставлять свое фото и оно должно добавлять в firebase.Посмотрел различные примеры как это делать, понял принцип, но как бы я не пробовал у меня не добавляется фотография firebase и не выводиться в CircleImageView. Помогите понять в чем ошибка.
Вот мои разрешения в Манифесте
<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"/>
Вот сама активити настроек
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+"%");
}
});
}
}
}