Firebase管理员Java:如何使用动态查询进行数据库引用

时间:2017-05-30 15:11:11

标签: java firebase firebase-realtime-database firebase-admin

在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) {
        }
    });

提前致谢!

0 个答案:

没有答案