我正在尝试使用firebase创建一个聊天应用程序,创建了一个Listener
响应添加数据库中的项目,由于添加了项目,所有用户都应该收到一个toast消息,对于某些人来说我之所以遇到以下问题。
只使用正在使用的手机添加信息,获取吐司,而其他人则不会。见附件。
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
//here should start the listener
mChildRefrence.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String ItemKey = dataSnapshot.getKey();
String msg = dataSnapshot.child("new_message").getValue(String.class);
String senderName = dataSnapshot.child("senderName").getValue(String.class);
String senderUid = dataSnapshot.child("senderUid").getValue(String.class);
String receiverUid = dataSnapshot.child("receiverUid").getValue(String.class);
String receiverName = dataSnapshot.child("receiverName").getValue(String.class);
int seen = dataSnapshot.child("seen").getValue(Integer.class);
// String timeMsgSent = dataSnapshot.child("timeMsgSent").getValue(String.class);
boolean inserted = msgTable.insertData(ItemKey, senderName, senderUid, receiverName, receiverUid, msg, seen, "timestamp");
if (inserted)
Log.d("test data", "info has been inserted");
else
Log.d("test data", "info has not been inserted");
count++;
Toast.makeText(getBaseContext(), count+" "+msg, Toast.LENGTH_SHORT).show();
}
})
}