Android PushNotification第一次截击错误和第二次截击错误
当我第一次调用PrepareNotifications to Admin函数时,错误响应(截击错误)即将到来。当我再次调用这个函数时,只有它成功了。它意味着第二次工作 有人能找出错误吗Android PushNotification第一次截击错误和第二次截击错误,android,firebase-cloud-messaging,Android,Firebase Cloud Messaging,当我第一次调用PrepareNotifications to Admin函数时,错误响应(截击错误)即将到来。当我再次调用这个函数时,只有它成功了。它意味着第二次工作 有人能找出错误吗 private void PrepareNotificationToAdmin() { database.collection("xxxx").document("xxxx").get() .addOnSuccessListener(new OnSuccessL
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);
}
私人作废准备通知管理员(){
database.collection(“xxxx”).document(“xxxx”).get()
.addOnSuccessListener(新的OnSuccessListener(){
@凌驾
成功时公共无效(文档快照文档快照){
AdminDeviceToken=documentSnapshot.getString(“deviceToken”);
}
});
通知_TITLE=“新基拉南注册”;
NOTIFICATION_MESSAGE=loggedUserId+“-已将新的kiranam注册为”+KiranamName;
JSONObject通知=新建JSONObject();
JSONObject notifcationBody=新JSONObject();
试一试{
notifcationBody.put(“标题”,通知标题);
notifcationBody.put(“消息”,通知消息);
通知。提交(“收件人”,AdminDeviceToken);
notification.put(“数据”,notifcationBody);
}捕获(JSONException e){
Log.e(标记“onCreate:+e.getMessage());
}
发送通知(通知);
}
私有void sendNotification(JSONObject通知){
JsonObjectRequest JsonObjectRequest=新的JsonObjectRequest(FCM_API,通知,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
Log.i(标记“onResponse:+response.toString());
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
新的OneToast(Register.this,“请求错误”);
//Todo:仅第一次出现请求错误//
Log.i(标记“onErrorResponse:未工作”);
}
}) {
@凌驾
公共映射getHeaders()引发AuthFailureError{
Map params=新的HashMap();
参数put(“授权”,serverKey);
参数put(“内容类型”,contentType);
返回参数;
}
};
getInstance(getApplicationContext()).addToRequestQueue(jsonObjectRequest);
}
最后,我找到了一个解决方案。主要问题是由于从Admin服务器获取设备令牌的延迟。在此之前,正在处理通知函数,结果是失败
现在这个问题已经解决。@david wasser,请就此向我提出建议。