0

I am working on android studio with firebase. I created login and signup activities. The user can also update there profile picture and display name. On retrieving the user profile, I am getting the displayname, email, provider, UID and profile picture.

In emulator image shows in the imageview but when running it on real device image doesnot appear.

I have also added setPersistanceEnabled(true) but it doesnot solve. I have pasted my code by which user profile is created and retrieved.

   private void updateProfile(String uName, Uri uri) {
   UserProfileChangeRequest userProfileChangeRequest = new 
   UserProfileChangeRequest.Builder()
                .setDisplayName(uName)
                .setPhotoUri(uri)
                .build();
   user.updateProfile(userProfileChangeRequest);
   mRef.child("Name").setValue(uName);
   mRef.child(uri.getLastPathSegment()).setValue(uri.toString());
   StorageReference profileStorage = 
   mStorage.child(uri.getLastPathSegment());
        profileStorage.putFile(uri);
        showMessage("Upload Successful");
        Intent intent = new Intent(this,UserHome.class);
        startActivity(intent);
    }else{
        showMessage("Upload Profile Picture");
    }
    }


    ////// for retrieving and displaying ///////

    String namee = user.getDisplayName();
    Uri uri = mAuth.getCurrentUser().getPhotoUrl();        
    Glide.with(UserHome.this).load(uri).into(imageView);        
    textView.setText(user.getDisplayName());        
    Log.v("data",user.getPhotoUrl().toString());
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mohammad Maaz
  • 137
  • 1
  • 8
  • did you submit project sha checksum on firebase console? – SAKhan Feb 07 '19 at 09:58
  • i just remembered, the SDK setup in firebase console saying, Run your app to verify installataion, never finishes – Mohammad Maaz Feb 07 '19 at 11:17
  • https://stackoverflow.com/questions/39144629/how-to-add-sha-1-to-android-application check this – SAKhan Feb 07 '19 at 16:37
  • my app is connected to firebase but the main problem is image not showing up in real device at all. However, in emulator the image is shown once it gets uploaded, on restarting the app in emulator the image disappears – Mohammad Maaz Feb 08 '19 at 07:01

1 Answers1

0

When you update the user profile after selecting an image from phone storage it uses your phone's image URI and updates the user account with it. And it displays it for the first before closing or signing out because it is still in the cache. But when you reopen or login to that account that cache is cleared and it does not display that image. So, to overcome this issue you have to upload that image to firebase storage first then get the link of the image and update the current user's photo with that link. It will be a universal link and will be working even after you have reopened your app or re-login to your account.

Nayana Chandran
  • 1,416
  • 1
  • 16
  • 30
Kashif Masood
  • 286
  • 1
  • 6