我正在尝试将json数据发送到fcm服务器URL,当我从fcm发送通知时,我收到默认通知,并且我的自定义通知未显示。我想实现这个,以便调用我的onMessageReceived()
。每次我尝试发送时都会收到此错误。
04-11 13:39:22.244 21208-26145/com.myapp E/Volley: [28124] BasicNetwork.performRequest: Unexpected response code 400 for https://fcm.googleapis.com/fcm/send/
04-11 13:39:22.244 21208-21208/com.myapp E/!_@@_Errors--: com.android.volley.ServerError
这就是我所拥有的,
private void sendFCMPush() {
final String Legacy_SERVER_KEY = getResources().getString(R.string.google_api_key);
String msg = "this is test message,.,,.,.";
String title = "my title";
String token = "MY_TOKEN";
JSONObject obj = null;
JSONObject objData = null;
JSONObject dataobjData = null;
try {
obj = new JSONObject();
objData = new JSONObject();
objData.put("body", msg);
objData.put("title", title);
dataobjData = new JSONObject();
dataobjData.put("text", msg);
dataobjData.put("title", title);
obj.put("to", token);
//obj.put("priority", "high");
obj.put("notification", objData);
obj.put("data", dataobjData);
Log.d("!_@rj@_@@_PASS:>", obj.toString());
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsObjRequest = new JsonObjectRequest(com.android.volley.Request.Method.POST, API_URL_FCM, obj,
new com.android.volley.Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("!_@@_SUCESS", response + "");
}
},
new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("!_@@_Errors--", error + "");
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Authorization", "key=" + Legacy_SERVER_KEY);
params.put("Content-Type", "application/json; charset=utf-8");
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
int socketTimeout = 1000 * 60;// 60 seconds
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
jsObjRequest.setRetryPolicy(policy);
requestQueue.add(jsObjRequest);
}
我一直在尝试不同的方式,但它们都不适合我。请帮帮我。