gpt4 book ai didi

java - com.firebase.client.ServerValue.TIMESTAMP 响应什么?

转载 作者:行者123 更新时间:2023-11-29 21:03:22 24 4
gpt4 key购买 nike

我正在尝试在 Web 上使用 Firebase 构建聊天应用程序,并创建 Android 客户端。在我的网络应用程序中,我将 Firebase 服务器的时间戳与消息一起发送,但我在 Android 上似乎遇到了一些麻烦。使用 Firebase 的 Android 开源聊天应用程序,我使用了默认的 Chat.java 类,但是当我尝试使用 ServerValue.TIMESTAMP 发送时间戳时,我收到一个错误,因为我认为它会返回一个 int 但它返回一个 Map

现在我正在使用一种解决方法并从设备本身获取时间,但如果跨时区的人将要使用该应用程序,我会尝试保持一致并减少出错的空间。

这是我目前围绕 block 的工作

private void sendMessage() {
EditText inputText = (EditText)findViewById(R.id.messageInput);
String input = inputText.getText().toString();
Long timestamp = System.currentTimeMillis()/1000;
if (!input.equals("")) {
// Create our 'model', a Chat object
Chat chat = new Chat(name, input, timestamp, userID);
// Create a new, auto-generated child of that chat location, and save our chat data there
ref.push().setValue(chat);
inputText.setText("");
}
}

和聊天.java

公开课聊天{

private String from;
private String text;
private int userID;
private Long timestamp;

// Required default constructor for Firebase object mapping
@SuppressWarnings("unused")
private Chat() { }

Chat(String from, String text, Long timestamp, int userID) {
this.from = from;
this.text = text;
this.timestamp = timestamp;
this.userID = userID;
}

public String getFrom() {
return from;
}

public String getText() {
return text;
}

public Long getTimestamp() {
return timestamp;
}

public int getuserID() {
return userID;
}

最佳答案

评论太长了。我的意思更多的是像这样的东西,我在很多场合都用过。

var chatUserRef = new Firebase("your url to chat user");
chatUserRef.child('time')
.set(Firebase.ServerValue.TIMESTAMP)
.on('value', function(snapshot){
var current_server_time = snapshot.val();
});

虽然是javascript,但是Java中的原理应该是一样的。

关于java - com.firebase.client.ServerValue.TIMESTAMP 响应什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25304422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com