NCMBPushService extends NCMBService { public JSONObject sendPush(JSONObject params) throws NCMBException { if (params == null) { throw new NCMBException(NCMBException.INVALID_JSON, "params must not be null"); } else if (params.has("deliveryTime") && params.has("immediateDeliveryFlag")) { throw new NCMBException(NCMBException.INVALID_JSON, "'deliveryTime' and 'immediateDeliveryFlag' can not be set at the same time."); } if (!params.has("deliveryTime")) { try { params.put("immediateDeliveryFlag", true); } catch (JSONException e) { throw new NCMBException(NCMBException.INVALID_JSON, "prams invalid JSON."); } } RequestParams request = createRequestParams(null, params, null, NCMBRequest.HTTP_METHOD_POST); NCMBResponse response = sendRequest(request); if (response.statusCode != NCMBResponse.HTTP_STATUS_CREATED) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, "Created failed."); } return response.responseData; } NCMBPushService(NCMBContext context); JSONObject sendPush(JSONObject params); void sendPushInBackground(final JSONObject params, ExecuteServiceCallback callback); JSONObject updatePush(String pushId, JSONObject params); void updatePushInBackground(final String pushId, final JSONObject params, final ExecuteServiceCallback callback); void deletePush(String pushId); void deletePushInBackground(String pushId, DoneCallback callback); NCMBPush fetchPush(String pushId); void fetchPushInBackground(final String pushId, final FetchCallback callback); List searchPush(JSONObject conditions); void searchPushInBackground(JSONObject conditions, final SearchPushCallback callback); void sendPushReceiptStatusInBackground(String pushId, ExecuteServiceCallback callback); static final String SERVICE_PATH; static final int HTTP_STATUS_PUSH_CREATED; static final int HTTP_STATUS_PUSH_UPDATED; static final int HTTP_STATUS_PUSH_DELETED; static final int HTTP_STATUS_PUSH_GOTTEN; static final int HTTP_STATUS_PUSH_RECEIPTSTATUS; }
@Test public void sendPush() throws Exception { NCMBPushService pushService = (NCMBPushService) NCMB.factory(NCMB.ServiceType.PUSH); JSONObject params = new JSONObject(); params.put("title", "title"); params.put("message", "message"); params.put("target", new JSONArray("[android]")); JSONObject json = pushService.sendPush(params); Assert.assertEquals("7FrmPTBKSNtVjajm", json.getString("objectId")); }