Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SendPushNotifications {
- public void triggerFirebaseNotificationRequest(String time_code, String business_id,
- String name, String quantity, String attendant_name,
- String attendant_id) {
- JSONObject json = new JSONObject();
- JSONObject manJson = new JSONObject();
- try {
- manJson.put("message", "New Sales");
- manJson.put("type", "sale");
- manJson.put("time_code", time_code);
- manJson.put("business_id", business_id);
- manJson.put("name", name);
- manJson.put("quantity", quantity);
- manJson.put("attendant_name", attendant_name);
- manJson.put("attendant_id", attendant_id);
- json.put("to", "/topics/sales-updates");
- json.put("data", manJson);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- String json_str = json.toString();
- Log.d("jsorn_to_firebase", json_str);
- try {
- HttpClient client = new DefaultHttpClient();
- HttpPost httpPost = new HttpPost("https://fcm.googleapis.com/fcm/send");
- httpPost.setEntity(new StringEntity(json_str));
- // httpPost.setHeader("Accept", "application/json");
- httpPost.setHeader("Authorization", "key=AIzaSyAIIT2f8nMXh6HDHNmX3rI7EOcYaBzsV3U");
- httpPost.setHeader("Content-type", "application/json");
- Log.d("firebase_notif_request", "true");
- HttpResponse response = client.execute(httpPost);
- String responseStr = EntityUtils.toString(response.getEntity());
- Log.d("request_made7", "reached");
- Log.d("firebase_notif_resp", responseStr);
- Log.d("firebase_notif_resp", "true");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- } catch (ClientProtocolException e) {
- //sync failed so we rest the syncing icon
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement