无法使用Firebase数据库在导航头中显示配置文件图像

时间:2018-08-17 13:37:52

标签: android image firebase firebase-realtime-database user-profile

Firebase无法显示在Firebase数据库上上传的图像。使用调试查找变量,似乎有图像的URL,但是当我运行应用程序时,它没有显示在Navigation标头上。像这样:that image is the placeholder

these are the variables

这是代码

    mAuth = FirebaseAuth.getInstance();
    UserRef = FirebaseDatabase.getInstance().getReference().child("Users");
    currentUserID = Objects.requireNonNull(mAuth.getCurrentUser()).getUid();

    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle("ES     ");
    toolbar.setTitleTextAppearance(this, R.style.toolbar_textAppearance);
    setSupportActionBar(toolbar);

    drawerLayout = findViewById(R.id.drawer_layout);
    NavigationView navigationView = findViewById(R.id.nav_view);
    NavProfileImage = navigationView.getHeaderView(0).findViewById(R.id.profile_image);
    NavTextView = navigationView.getHeaderView(0).findViewById(R.id.text_Nickname);
    navigationView.setNavigationItemSelectedListener(this);

    UserRef.child(currentUserID).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                Log.d("image Path", NavProfileImage.toString());
                if (dataSnapshot.hasChild("nickname")) {
                    String nickname = dataSnapshot.child("nickname").getValue(String.class);
                    NavTextView.setText(nickname);
                }
                if (dataSnapshot.hasChild("profileImage")) {
                    String image = dataSnapshot.child("profileImage").getValue(String.class);
                    Picasso.get().load(image).placeholder(R.mipmap.ic_launcher).into(NavProfileImage);
                } else {
                    Toast.makeText(HomeActivity.this, "Profile name do not exists...", Toast.LENGTH_SHORT).show();
                }
            }
        }

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

        }
    });

0 个答案:

没有答案