1
我試圖在Firebase中的帖子中添加時間戳,但我很遺憾沒有成功。我已經嘗試了很多來自stackoverflow的建議,但都沒有成功。請幫助我如何在每篇文章下添加時間戳字段。將時間戳記發佈到Android Firebase數據庫不起作用
我想知道我的代碼有什麼問題。
final DatabaseReference newPost = mDatabase.push();
mDatabaseUser.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Long timestamp = (Long) dataSnapshot.getValue();
System.out.println(timestamp);
newPost.child("title").setValue(title_val);
newPost.child("desc").setValue(desc_val);
newPost.child("image").setValue(downloadUrl.toString());
newPost.child("uid").setValue(mCurrentUser.getUid());
newPost.child("username").setValue(dataSnapshot.child("name").getValue()).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
startActivity(new Intent(PostActivity.this, MainActivity.class));
}
}
});
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
mDatabaseUser.setValue(ServerValue.TIMESTAMP);
mProgress.dismiss();
火力地堡數據庫結構:
{
"Blog":{
"-Ke1osQRFVs0fuqx9n18":{
"desc":"again again",
"uid":"FBwMzHJGP4U10LnLOwluy4BVyJ52",
"username":"OziBoo"
}
},
"Users":{
"vi6Qd1AafidNGGV4roBhdLPZYGN2":{
"image":"firebasestorage.googleapis.com/v0/b/agrodesk-b30ff.appspot.com/...",
"name":"Ozi"
}
}
}
向我們展示您的Firebase結構以及您想實現的目標? –
{ 「博客」:{ 「-Ke1osQRFVs0fuqx9n18」:{ 「說明」: 「再一次」, 「UID」: 「FBwMzHJGP4U10LnLOwluy4BVyJ52」, 「用戶名」: 「OziBoo」 }} , 「用戶「:{ 」vi6Qd1AafidNGGV4roBhdLPZYGN2「:{ 」image「:」https://firebasestorage.googleapis.com/v0/b/agrodesk-b30ff.appspot.com/o/Profile_images%2Fcropped-377289343.jpg?alt=media&token = 5cf3ae8f-66af-43bd-bb8e-a9ee8e1250ff」, 「名」: 「OZI」 }} } 之前 –
感謝您的幫助 –