小编Olc*_*mez的帖子

如何使用FCM向特定用户发送通知?

我为FCM准备了接收器,可以向所有设备发送通知.

带有此链接的gcm-http.googleapis.com/gcm/send可以发送给已注册的目标用户并将其发布到目标设备,如下面的json:

 {
     "notification": {
                "title": "sample Title",
                "text": "sample text"   },   
        "to" : "[registration id]"
         }
Run Code Online (Sandbox Code Playgroud)

但是,我需要通过电子邮件或姓名等向我选择的目标用户发送通知.例如:

{
     "notification": {
                "title": "sample Title",
                "text": "sample text"   },   
        "to" : "[email or name or sex ...]"
         }
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我是否需要创建Web服务器或其他东西?

notifications android firebase google-cloud-messaging firebase-cloud-messaging

23
推荐指数
1
解决办法
3万
查看次数

如何在android中删除ValueEventListener?

我一直在使用 firebase 2 周。拜托我需要你的帮忙。

   public void closeReadRef() {
    if (readRef != null)
        readRef.removeEventListener(listener);
}
Run Code Online (Sandbox Code Playgroud)

上面的代码必须删除我的侦听器,但它不起作用。我在onPause, onDestroy, 中调用此方法onStop

    @Override
public void onStart() {
    FirebaseUtility.getInstance().closeReadRef();
    super.onStart();
}

@Override
public void onPause() {
    super.onPause();
}

@Override
public void onResume() {
    super.onResume();
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么 ?为什么我不能取消监听器?谢谢你。

编辑

我在 Activity 内的 onCreate() 中调用以下方法。

 public void setReadTrueInFireBase(final String currentID, final String location) {
    instance.currentID = currentID;
    instance.location = location;
    readRef = FirebaseDatabase.getInstance().getReferenceFromUrl(Constant.FIREBASE_DATABASE_URL);
    readRef.child("conversations").child(location).addValueEventListener(listener);
}
Run Code Online (Sandbox Code Playgroud)

android listener firebase firebase-realtime-database

1
推荐指数
1
解决办法
4615
查看次数