0
當我使用volley將請求發送到服務器時,它不起作用並引發運行時錯誤。String使用volley從FirebaseMessagingService請求不起作用
public class MyFCMService extends FirebaseMessagingService {
String url, title, message;
String category_id;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
title = remoteMessage.getData().get("title");
message = remoteMessage.getData().get("message");
String id = remoteMessage.getData().get("ID");
if (check(id).equals("6")) {
sendNotification(title, message);
} else {
sendNotification("khalid", "khalid");
}
}
public String check(String id) {
url = "http://www.tobeacademy.com/api/get_post/?post_id=" + id;
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray array = jsonObject.getJSONArray("post");
category_id = array.getJSONObject(0).getString("id");
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
Volley.newRequestQueue(this).add(stringRequest);
return category_id;
}