Java 按主题使用FCM推送通知 列表项

Java 按主题使用FCM推送通知 列表项,java,android,firebase-cloud-messaging,Java,Android,Firebase Cloud Messaging,1-问题是,当用户向卖家发送订单时,通知不会出现,IDE不会出现错误 问题出在哪里? 2-这里有代码: 在用户类别中: 在此处输入代码: 方法调用 final String timestamp = ""+System.currentTimeMillis(); prepareNotificationMessage(timestamp); prepareNotificationMessage(orderId,message); 方法是:

1-问题是,当用户向卖家发送订单时,通知不会出现,IDE不会出现错误 问题出在哪里?

2-这里有代码:

在用户类别中:

在此处输入代码:

方法调用

       final String timestamp = ""+System.currentTimeMillis();
       prepareNotificationMessage(timestamp);
    prepareNotificationMessage(orderId,message);
方法是:

   private void prepareNotificationMessage(String orderId){

    //prepare data for notification
    String NOTIFICATION_TOPIC = "/topics/"+Constants.FCM_TOPIC;//same as subscriped by User
    String NOTIFICATION_TITLE = "New Order"+orderId;
    String NOTIFICATION_MESSAGING = "تهانينا لديك طلب جديد";
    String NOTIFICATION_TYPE = "NewOrder";


    //prepare json
    JSONObject notificationJo = new JSONObject();
    JSONObject notificationBodyJo = new JSONObject();

    try {
        //what to send
        notificationBodyJo.put("notificationType",NOTIFICATION_TYPE);
        notificationBodyJo.put("buyerUid",firebaseAuth.getUid());
        notificationBodyJo.put("sellerUid",shopUid);
        notificationBodyJo.put("orderId",orderId);
        notificationBodyJo.put("notificationTitle",NOTIFICATION_TITLE);
        notificationBodyJo.put("notificationMessage",NOTIFICATION_MESSAGING);

        //where to send

 notificationJo.put("to",NOTIFICATION_TOPIC);
 notificationJo.put("data",notificationBodyJo);
    }
    catch (Exception e){
   Toast.makeText(this,""+e.getMessage(),Toast.LENGTH_SHORT).show();
    }
sendFcmNotification(notificationJo,orderId);
}
卖方代码如下:

方法调用

       final String timestamp = ""+System.currentTimeMillis();
       prepareNotificationMessage(timestamp);
    prepareNotificationMessage(orderId,message);
方法:

private void prepareNotificationMessage(String orderId,String message){
    //when user places order ,send notification to seller

    //prepare data for notification
    String NOTIFICATION_TOPIC = "/topics/"+ Constants.FCM_TOPIC;//same as subscriped by User
    String NOTIFICATION_TITLE = "Your Order"+orderId;
    String NOTIFICATION_MESSAGING = ""+message;
    String NOTIFICATION_TYPE = "OrderStatusChanged";

    //prepare json
    JSONObject notificationJo = new JSONObject();
    JSONObject notificationBodyJo = new JSONObject();
    try {
        //what to send
        notificationBodyJo.put("notificationType",NOTIFICATION_TYPE);
        notificationBodyJo.put("buyerUid",orderBy);
        notificationBodyJo.put("sellerUid",firebaseAuth.getUid());
        notificationBodyJo.put("orderId",orderId);
        notificationBodyJo.put("notificationTitle",NOTIFICATION_TITLE);
        notificationBodyJo.put("notificationMessage",NOTIFICATION_MESSAGING);
       //where to send
       
   notificationJo.put("to",NOTIFICATION_TOPIC);
        notificationJo.put("data",notificationBodyJo);
    }catch (Exception e){
        Toast.makeText(this,""+e.getMessage(),Toast.LENGTH_SHORT).show();
    }
    sendFcmNotification(notificationJo);
}

private void sendFcmNotification(JSONObject notificationJo) {
    //send Volley Request
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest("https://fcm.googleapis.com/fcm/send", notificationJo, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
       //after sending fcm start order details activity,sent

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
   //id failed sending fcm, still start order details activity

        }
    }){
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            //put required headers
            Map<String,String >headers = new HashMap<>();
            headers.put("Content-Type","application/json");
            headers.put("Authorization","key="+Constants.FCM_KEY);
            return headers;
        }
    };
    //enque the Volley request
    Volley.newRequestQueue(this).add(jsonObjectRequest);
}

}

这个问题的解决方案是什么