第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何檢索當(dāng)前用戶 ID 并放入片段

如何檢索當(dāng)前用戶 ID 并放入片段

qq_笑_17 2022-01-19 10:39:16
我正在制作一個(gè)帳戶片段,所以我想檢索name和image數(shù)據(jù),但它使我的應(yīng)用程序強(qiáng)制關(guān)閉:這是我的帳戶片段:import android.content.Context;import android.content.Intent;import android.net.Uri;import android.nfc.Tag;import android.os.Bundle;import android.support.annotation.NonNull;import android.support.v4.app.Fragment;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.TextView;import android.widget.Toast;import com.bumptech.glide.Glide;import com.bumptech.glide.request.RequestOptions;import com.google.android.gms.tasks.OnCompleteListener;import com.google.android.gms.tasks.Task;import com.google.firebase.auth.FirebaseAuth;import com.google.firebase.auth.FirebaseUser;import com.google.firebase.firestore.DocumentSnapshot;import com.google.firebase.firestore.FirebaseFirestore;import com.google.firebase.storage.FirebaseStorage;import com.google.firebase.storage.StorageReference;import java.util.ArrayList;import java.util.List;import java.util.zip.Inflater;import de.hdodenhof.circleimageview.CircleImageView;import static android.support.constraint.Constraints.TAG;/** * A simple {@link Fragment} subclass. */public class AccountFragment extends Fragment {  private StorageReference storageReference;  private FirebaseAuth firebaseAuth;  private FirebaseFirestore firebaseFirestore;  private Uri mainImageURI = null;  private String user_id;  private TextView accountName;  private CircleImageView accountImage;  public AccountFragment() {    // Required empty public constructor  }  @Override  public View onCreateView(LayoutInflater inflater, ViewGroup container,    Bundle savedInstanceState) {    // Inflate the layout for this fragment    View view = inflater.inflate(R.layout.fragment_account, container, false);    getUser();    return view;  }          });  }}
查看完整描述

3 回答

?
互換的青春

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊

這對(duì)我有用:


//in Class definition.

private FirebaseFirestore firebaseFirestore;

private FirebaseAuth firebaseAuth;

private FirebaseUser currentUser;


//Declareation in Oncreate()

currentUser = firebaseAuth.getCurrentUser();

userId = currentUser.getUid();

private void setUserName() {

    /*

        Assign the value of profile_name_of field in the document of the current user

        under Users collection.

        pre:---.

        post: changes the value of the instance variable of username.

     */


    firebaseFirestore.collection("Users").document(userId)

            .get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {


        @Override

        public void onComplete(@NonNull Task<DocumentSnapshot> task) {

            DocumentSnapshot documentSnapshot = task.getResult();


            if(documentSnapshot.exists()){


                List<String> list = new ArrayList<>();

                Map<String, Object> map = documentSnapshot.getData();


                if(map != null){


                    for(Map.Entry<String, Object> entry : map.entrySet()){

                        list.add(entry.getValue().toString());

                    }


                    username = list.get(0);

                    Toast.makeText(context,

                          "username"+username,

                          Toast.LENGTH_LONG).show();

                }

            }

        }

    });

}



查看完整回答
反對(duì) 回復(fù) 2022-01-19
?
慕蓋茨4494581

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊

顯然您正在使用未實(shí)例化的變量來(lái)獲取數(shù)據(jù)。嘗試更改它:


protected void getUser() {


FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();


user_id = currentUser.getUid();

....

}


查看完整回答
反對(duì) 回復(fù) 2022-01-19
?
慕的地6264312

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊

tol獲取用戶的uid,只需使用以下幾行代碼:


FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();

if (firebaseUser != null) {

    String uid = firebaseUser.getUid(); //Do what you need to do with your uid

}

firebaseUser檢查無(wú)效性也很重要。


查看完整回答
反對(duì) 回復(fù) 2022-01-19
  • 3 回答
  • 0 關(guān)注
  • 208 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)