Place profile photo in Nav Header

I have a question about creating an App.

I need to put the user's profile picture on my Nav_Header_Tela_Princial.

insert the description of the image here

I already have a profile screen, but I need to use the same image as the user's profile screen for my NAV.

insert the description of the image here

The profile screen is working properly, I can already save the image, but I just need to use the same Uri on the other screen.

I haven't I managed to create nothing code because I have no idea what to search for. I need a light on how to accomplish this.

Protected void onCreate (bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R. layout.activity_settings);

    Bundle bundle = new Bundle();
    bundle.putString("foto", resultUri.toString());
    Intent intent = new Intent(SettingsActivity.this, TelaPrincipalActivity.class);
    intent.putExtras(bundle);
    startActivity(intent);

    edtNameField = (EditText) findViewById(R.id.edtName);
    edtPhoneField = (EditText) findViewById(R.id.edtPhone);

    imgProfileImage = (ImageView) findViewById(R.id.imgProfileImage);

    btnBack = (Button) findViewById(R.id.btnBack);
    btnConfirm = (Button) findViewById(R.id.btnConfirm);

    mAuth = FirebaseAuth.getInstance();
    userID = mAuth.getCurrentUser().getUid();
    mCustomerDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(userID);

    getUserInfo();

    imgProfileImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_PICK);
            intent.setType("image/*");
            startActivityForResult(intent, 1);
        }
    });

This would be the Activity that should receive the data from the Uri.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tela_principal);

    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();

    String foto = bundle.getString("foto");

    btnTest = (Button) findViewById(R.id.BtnTest);
    btnTest.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            openBtnTest();
        }
    });

    edtSearch = (TextView) findViewById(R.id.edtSearch);

    edtSearch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            search();
        }
    });
Author: Edi, 2018-09-02

1 answers

If what you want is to use the database photo to display in Nav_Header_Foto you will need to redeem this database Url, and this is done according to your application. Here is an example of how to redeem a database value (in this case Firebase Realtime Database) to display when loading activity (loading into activity's OnCreate method):

GetDados also has the example of creating user.

Now, if you just want pass the information from one activity to another and I suppose you know something about manipulating the View elements (the r.id.findViewById and etc...)

You can send the data you want through the Bundle .

Just adapt this example in some event in the class of your activity, where urlFoto is the variable already with the url and the intent is used to make the transition between the activities:

 Bundle bundle = new Bundle();
 bundle.putString("foto", urlfoto.toString());

 Intent intent = new Intent(activityAtual.this, proximaActivity.class);
 intent.putExtras(bundle);

 startActivity(intent);

Now in proximaActivity.java you redeem the values with the following code:

 Intent intent = getIntent();
 Bundle bundle = intent.getExtras();

 String foto = bundle.getString("foto");

Just use your url and set it to The View element you want.

 0
Author: Jhonatan Raul, 2018-09-03 04:50:54