title: Upload profile image for a user Firebase
body: <p>I am trying to add an image to the user information in the real time database(firebase) for android. I have uploaded the image on the firebase storage but how will I be able to add the image in the database for that user?</p>
  
  <p>Code Below:</p>
  
  <pre><code>//inside onCreate() method
  
  img.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent i=new Intent(Intent.ACTION_PICK);
              i.setType("image/*");
              startActivityForResult(i,request_code);
          }
      });
  </code></pre>
  
  <p>Here I am clicking on the imageview, so I will be able to change it and get an image from the gallery.</p>
  
  <p>Here I authenticate the user and send data to the database:</p>
  
  <pre><code> auth.createUserWithEmailAndPassword(email, password)
                      .addOnCompleteListener(StudentSignUpActivity.this, new OnCompleteListener&lt;AuthResult&gt;() {
                          @Override
                          public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                              Toast.makeText(getApplicationContext(), "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
                              progressBar.setVisibility(View.GONE);
                              // If sign in fails, display a message to the user. If sign in succeeds
                              // the auth state listener will be notified and logic to handle the
                              // signed in user can be handled in the listener.
                              if (!task.isSuccessful()) {
                                  Toast.makeText(getApplicationContext(), "Authentication failed." + task.getException(),
                                          Toast.LENGTH_SHORT).show();
                              } else {
                                  startActivity(new Intent(StudentSignUpActivity.this, HomeActivity.class));
                                  finish();
                              }
                          }
                      });
  
  mCurrentUser=FirebaseAuth.getInstance().getCurrentUser();
              DatabaseReference newStudent=mDatabase.push();
              newStudent.child("email").setValue(email);
              newStudent.child("password").setValue(password);
              newStudent.child("name").setValue(name);
              newStudent.child("date").setValue(dates);
              newStudent.child("phone").setValue(number);
              newStudent.child("uid").setValue(mCurrentUser.getUid());
  
  
  //outside of onCreate()
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if(requestCode==request_code&amp;&amp;resultCode==RESULT_OK){
          Uri uri=data.getData();
          StorageReference filepath=mStorage.child("Images").child(uri.getLastPathSegment());
          filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
              @Override
              public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
  
              }
          });
      }
  }
  </code></pre>
  
  <p>In the above code I have uploaded the image to the firebase storage. Now how will i be able to add that image as a child for a specific user.</p>
  
  <p>I think I need to do something like this:</p>
  
  <pre><code> newStudent.child("image").setValue(uri_here);
  </code></pre>
  
  <p>But I am unable to figure how to get the uri of the image and how to add that uri in the <code>setValue()</code> since its in another method.</p>