问题描述
我试图建立过在网络上使用火力地堡一个聊天应用程序,以及创建和Android客户端。
在我的web应用程序,我送了火力地堡服务器的时间戳的消息一起,但我似乎有在Android上有点麻烦。
使用Android的火力地堡的开源聊天应用程序,我已经使用了默认Chat.java类,但是当我尝试使用发送时间戳 ServerValue.TIMESTAMP
我得到一个错误,因为我相信它会返回一个 INT
但它返回一个地图
。
I'm trying to build off a chat application using Firebase on the web, and create and Android client.In my web app, I send the Firebase Server's time stamp along with the message, but I seem to be having a bit of trouble on Android.Using Firebase's Opensource chat app for Android, I have used the default Chat.java class, but when I try to send the time stamp using ServerValue.TIMESTAMP
I get an error because I assume it would return an int
but it returns a Map
.
现在我用一种变通方法,并充分利用设备本身的时间,但我试图保持一致,减少错误的余地,如果跨时区的人们将要使用的应用程序。
Right now I'm using a workaround and getting the time from the device itself, but I'm trying to keep it consistent and reduce room for error if people across time zones are going to be using the app.
下面是我目前的工作围绕块
Here's my current work around 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("");
}
}
和Chat.java
And Chat.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;
}
}
推荐答案
太长进入评论。我的意思是更多这样的事情,这是我场合的使用数量。
It is too long to go into comment. I meant more something like this, which I used on number of occasions.
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中一样。
It is in javascript nevertheless the principle should be the same in Java.
这篇关于这是什么com.firebase.client.ServerValue.TIMESTAMP与respong?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!