Search in sources :

Example 1 with RequestBody

use of dz.easy.androidclient.Model.RequestBody in project easy by MehdiBenmesa.

the class RegistrationIntentService method registerDeviceProcess.

private void registerDeviceProcess(String deviceName, String deviceId, String registrationId) {
    RequestBody requestBody = new RequestBody();
    requestBody.setDeviceId(deviceId);
    requestBody.setDeviceName(deviceName);
    requestBody.setRegistrationId(registrationId);
    requestBody.setEmail(App.getInstance().getEmail());
    Retrofit retrofit = new Retrofit.Builder().baseUrl(SERVER_URL).addConverterFactory(GsonConverterFactory.create()).build();
    RequestInterface request = retrofit.create(RequestInterface.class);
    Call<ResponseBody> call = request.registerDevice(requestBody);
    call.enqueue(new Callback<ResponseBody>() {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            ResponseBody responseBody = response.body();
            Intent intent = new Intent(App.REGISTRATION_PROCESS);
            intent.putExtra("result", responseBody.getResult());
            intent.putExtra("message", responseBody.getMessage());
            LocalBroadcastManager.getInstance(RegistrationIntentService.this).sendBroadcast(intent);
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : Retrofit(retrofit2.Retrofit) Intent(android.content.Intent) RequestBody(dz.easy.androidclient.Model.RequestBody) ResponseBody(dz.easy.androidclient.Model.ResponseBody)

Aggregations

Intent (android.content.Intent)1 RequestBody (dz.easy.androidclient.Model.RequestBody)1 ResponseBody (dz.easy.androidclient.Model.ResponseBody)1 Retrofit (retrofit2.Retrofit)1