当我尝试通过功能bt通过FCM将设备发送到设备推送通知时,我通过设备发送通知时,它将仅从实时DB中获得一个值。 在这里,第一个值是'sem'
final String sem = record;
DatabaseReference anewfeed = ndatabase.push();
anewfeed.child("sem").setValue(sem);
anewfeed.child("body").setValue(desc)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
progressDialog.dismiss();
// Toast.makeText(addnotice.this, desc , Toast.LENGTH_LONG).show();
Toast.makeText(addnotice.this, "Notice Sended Successfully" , Toast.LENGTH_LONG).show();
finish();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText(addnotice.this, "Error occurred " , Toast.LENGTH_LONG).show();
}
});
如果我互换sem和body的序列,那么它将获得body的值,当我手动将数据放入Firebase中时,该功能也可以正常工作。 这是我的带有onCreate触发器的功能代码
const functions = require('firebase-functions');
const admin =require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotice=functions.database.ref('/notice/{u_id}').onCreate((change, context) => {
var notice = change.val();
var topic = notice.sem;
var bd= notice.body;
console.log('sem is:', topic);
console.log('notification is:',bd);
var message = {
notification: {
title: ('Notice for '+topic+' sem'),
body: bd
},
topic: topic
};
admin.messaging().send(message);
} );
在控制台中显示body:undefine