我无法从交易中读取数据

时间:2019-06-16 04:10:48

标签: android google-cloud-firestore

将用户数据发送到firestore并再次登录时,系统未读取此代码,他在添加数据后已经加入(if),但返回失败,因为我认为firestore只接受写入,有什么解决办法吗?

if (snapshot.exists()) {
   return snapshot.getString("ID");
}

代码

FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
        DocumentReference documentReference = firebaseFirestore.collection("Players").document(saveSystem.LoadStringData("LoginType").equals("Facebook") ? "F" + saveSystem.LoadStringData("ID") : "G" + saveSystem.LoadStringData("ID"));
        firebaseFirestore.runTransaction(new Transaction.Function<Object>() {
            @Override
            public Object apply(Transaction transaction) throws FirebaseFirestoreException {
                DocumentSnapshot snapshot = transaction.get(documentReference);
                if (snapshot.exists()) {
                    return snapshot.getString("ID");
                } else {
                    HashMap<String, Object> hashMap = new HashMap<>();
                    hashMap.put("ID", saveSystem.LoadStringData("ID"));
                    return hashMap;
                }
            }
        }).addOnSuccessListener(new OnSuccessListener<Object>() {
            @Override
            public void onSuccess(Object aObject) {
                Toast.makeText(Test.this, "" + aObject, Toast.LENGTH_SHORT).show();
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {

            }
        });

对不起,简单的英语。

0 个答案:

没有答案