0
발리를 사용하여 서버에 요청을 보내면 작동하지 않고 런타임 오류가 발생합니다.발리를 사용한 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;
}