# Firebase Bild URL herausfinden



## Jonas31 (2. Nov 2018)

Hey Leute, 
In letzer zeit hab ich versucht ein Messenger zu Programmieren. Natürlich kann man bei einem Messenger Profilbilder verwenden die auf ein Server hochgeladen werden(Firebase Server) und von der Bild download Url in ein ImageView angezeigt wird. Mein Problem ist wenn ich versuche die download Url von dem Bild herauszufinden kommt bei mir dies immer: com.google....
Hier ist erstmal der Code:

```
public class AccountSettingsActivity extends AppCompatActivity {

    private DatabaseReference mUserDatabase;
    private FirebaseUser mFirebaseUser;
    StorageReference storageReference = FirebaseStorage.getInstance().getReference();

    CircleImageView mImage;
    TextView settings_name, settings_status;
    Button btn_image, btn_status;

    private static final int GALLERY_PICK = 1;

    ProgressDialog progressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_account_settings);

        mFirebaseUser = FirebaseAuth.getInstance().getCurrentUser();

        String uid = mFirebaseUser.getUid();

        mImage = (CircleImageView) findViewById(R.id.mImage);
        settings_name = (TextView) findViewById(R.id.settings_name);
        settings_status = (TextView) findViewById(R.id.settings_status);
        btn_image = (Button) findViewById(R.id.btn_image);
        btn_status = (Button) findViewById(R.id.btn_status);


        mUserDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(uid);
        mUserDatabase.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                StorageReference storageReference = FirebaseStorage.getInstance().getReference();
                String name = dataSnapshot.child("name").getValue().toString();
                String image = dataSnapshot.child("image").getValue().toString();
                String status = dataSnapshot.child("status").getValue().toString();
                String thumb_image = dataSnapshot.child("thumb_image").getValue().toString();

                settings_name.setText(name);
                settings_status.setText(status);
                Picasso.with(AccountSettingsActivity.this).load(image).into(mImage);

            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });

        btn_status.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(AccountSettingsActivity.this, Main2Activity.class);
                startActivity(intent);
            }
        });

        btn_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent galleryIntent = new Intent();
                galleryIntent.setType("image/*");
                galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(galleryIntent, "Bild auswählen"), GALLERY_PICK);

        /*
                CropImage.activity().setGuidelines(CropImageView.Guidelines.ON).start(AccountSettingsActivity.this);
        */
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == GALLERY_PICK && resultCode == RESULT_OK) {

            Uri imageUri = data.getData();

            CropImage.activity(imageUri).setAspectRatio(1, 1).start(AccountSettingsActivity.this);

        }
        if(requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE){

            CropImage.ActivityResult result = CropImage.getActivityResult(data);
            if(resultCode == RESULT_OK){

                progressDialog = new ProgressDialog(AccountSettingsActivity.this);
                progressDialog.setTitle("Profilbild ändern");
                progressDialog.setMessage("Bitte warten Sie bis der Vorgang abgeschlossen ist.");
                progressDialog.setCanceledOnTouchOutside(true);
                progressDialog.show();

                Uri resulturi = result.getUri();
                final String userid = mFirebaseUser.getUid();

                final StorageReference filepath = storageReference.child("profile_images/").child(userid + ".jpg");
                filepath.putFile(resulturi).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {

                        if(task.isSuccessful()){



                            String url = filepath.getDownloadUrl().toString();

                            mUserDatabase.child("image").setValue(url).addOnCompleteListener(new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@NonNull Task<Void> task) {
                                    if(task.isSuccessful()){

                                        progressDialog.dismiss();

                                    }
                                }
                            });

                            }else {
                            progressDialog.hide();
                            Toast.makeText(getApplicationContext(), "Ein fehler ist aufgetreten!", Toast.LENGTH_SHORT).show();
                        }

                    }
                });

            }else if(requestCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE){

                Exception error = result.getError();

            }
        }

    }

    public static String random(){

        Random random = new Random();
        StringBuilder stringBuilder = new StringBuilder();
        int randwomLength = random.nextInt(10);
        char tempChar;
                for (int i = 0; i < randwomLength; i++){

                    tempChar = (char) (random.nextInt(96) + 32);
                    stringBuilder.append(tempChar);

                }

        return stringBuilder.toString();
    }

}
```
Ich hoffe jemand kann mir helfen


----------

