推送通知凌空错误在第一次和第二次它的工作



当我第一次调用PrepareNotificationToAdmin函数时,ErrorResponse(VolleyError error(即将到来。当我再次调用这个函数时,只有它才能成功。这意味着第二次工作。

任何人都可以找出错误。


private void PrepareNotificationToAdmin() {
database.collection("xxxx").document("xxxx").get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
AdminDeviceToken = documentSnapshot.getString("deviceToken");
}
});
NOTIFICATION_TITLE = "New Kiranam Registration";
NOTIFICATION_MESSAGE =  loggedUserId + " - Has registered new kiranam as " + KiranamName;
JSONObject notification = new JSONObject();
JSONObject notifcationBody = new JSONObject();
try {
notifcationBody.put("title", NOTIFICATION_TITLE);
notifcationBody.put("message", NOTIFICATION_MESSAGE);
notification.put("to", AdminDeviceToken);
notification.put("data", notifcationBody);
} catch (JSONException e) {
Log.e(TAG, "onCreate: " + e.getMessage());
}
sendNotification(notification);
}
private void sendNotification(JSONObject notification) {
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(FCM_API, notification,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i(TAG, "onResponse: " + response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
new OneToast(Register.this, "Request error");
//Todo: request error on first time only//
Log.i(TAG, "onErrorResponse: Didn't work");
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Authorization", serverKey);
params.put("Content-Type", contentType);
return params;
}
};
MySingleton.getInstance(getApplicationContext()).addToRequestQueue(jsonObjectRequest);
}

最后,我得到了一个解决方案。主要问题是由于从管理员服务器获取设备令牌的延迟。在此之前,通知功能正在处理中,结果失败。

现在这个问题已经解决了。

相关内容

  • 没有找到相关文章

最新更新