在javascript中,我可以这样做:
var functions = require('firebase-functions');
exports.handleUserActivityUpdate = functions.database.ref('users/{userId}/{activityId}')
.onWrite(event => {
var userId = event.params.userId;
var activityId = event.params.activityId;
});
有没有办法在Java中做同样的事情?我尝试了以下但它没有工作:
final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("users/{userId}/{activityId}");
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
try {
System.out.println("Get key: " + dataSnapshot.getKey());
} finally {
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
提前致谢!