大家好我使用排球来进行API调用json请求工作正常。
但是现在在一个任务中我需要发送简单的平面文本,这是用于推送通知的简单设备令牌。
这是我的代码,请任何人都可以为我修改。
此
未显示任何回复或错误 private void updateDeviceToken() {
SharedPreferences settings = getBaseContext().getSharedPreferences("DEVICE_TOKEN_PREFS", Context.MODE_PRIVATE);
final String DeviceToken = settings.getString("DEVICE_TOKEN_STRING", null);
String URL = OrganizationModel.getUserBaseUrl() + dBhelper.getUserID() + "/fcm";
Log.i(TAG, URL);
try {
final String token = GetApiAccess();
RequestQueue requestQueue = Volley.newRequestQueue(this);
StringRequest jsonObjectRequest = new StringRequest(Request.Method.PUT, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i(TAG, "Update Success");
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String json = null;
NetworkResponse response = error.networkResponse;
if (response != null && response.data != null) {
switch (response.statusCode) {
case 400:
json = new String(response.data);
json = new DataHelper().trimMessage(json, "message");
if (json != null) new DataHelper().displayMessage(json);
break;
}
}
}
}) {
@Override
public String getBodyContentType() {
return "application/text; charset=utf-8";
}
@Override
public byte[] getBody() {
try {
return DeviceToken == null ? null : DeviceToken.getBytes("utf-8");
} catch (UnsupportedEncodingException uee) {
VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s",
DeviceToken, "utf-8");
return null;
}
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "Basic " + token);
//headers.put("Content-Type", "application/json; charset=utf-8");
// headers.put("Content-Type", "application/text");
// headers.put("charset", "charset=utf-8");
return headers;
}
};
requestQueue.add(jsonObjectRequest);
} catch (Exception e) {
}
}