use of com.androidnetworking.interfaces.OkHttpResponseListener in project Fast-Android-Networking by amitshekhariitbhu.
the class ApiTestActivity method checkOkHttpResponse.
public void checkOkHttpResponse(View view) {
AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY).addPathParameter("pageNumber", "0").addQueryParameter("limit", "3").setTag(this).setPriority(Priority.LOW).build().setAnalyticsListener(new AnalyticsListener() {
@Override
public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
Log.d(TAG, " bytesSent : " + bytesSent);
Log.d(TAG, " bytesReceived : " + bytesReceived);
Log.d(TAG, " isFromCache : " + isFromCache);
}
}).getAsOkHttpResponse(new OkHttpResponseListener() {
@Override
public void onResponse(Response response) {
if (response != null) {
if (response.isSuccessful()) {
Log.d(TAG, "response is successful");
try {
Log.d(TAG, "response : " + response.body().source().readUtf8());
} catch (IOException e) {
e.printStackTrace();
}
} else {
Log.d(TAG, "response is not successful");
}
} else {
Log.d(TAG, "response is null");
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER).addBodyParameter("firstname", "Suman").addBodyParameter("lastname", "Shekhar").setTag(this).setPriority(Priority.LOW).build().setAnalyticsListener(new AnalyticsListener() {
@Override
public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
Log.d(TAG, " bytesSent : " + bytesSent);
Log.d(TAG, " bytesReceived : " + bytesReceived);
Log.d(TAG, " isFromCache : " + isFromCache);
}
}).getAsOkHttpResponse(new OkHttpResponseListener() {
@Override
public void onResponse(Response response) {
if (response != null) {
if (response.isSuccessful()) {
Log.d(TAG, "response is successful");
try {
Log.d(TAG, "response : " + response.body().source().readUtf8());
} catch (IOException e) {
e.printStackTrace();
}
} else {
Log.d(TAG, "response is not successful");
}
} else {
Log.d(TAG, "response is null");
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
AndroidNetworking.upload(ApiEndPoint.BASE_URL + ApiEndPoint.UPLOAD_IMAGE).setPriority(Priority.MEDIUM).addMultipartFile("image", new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "test.png")).setTag(this).build().setAnalyticsListener(new AnalyticsListener() {
@Override
public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
Log.d(TAG, " bytesSent : " + bytesSent);
Log.d(TAG, " bytesReceived : " + bytesReceived);
Log.d(TAG, " isFromCache : " + isFromCache);
}
}).setUploadProgressListener(new UploadProgressListener() {
@Override
public void onProgress(long bytesUploaded, long totalBytes) {
Log.d(TAG, "bytesUploaded : " + bytesUploaded + " totalBytes : " + totalBytes);
Log.d(TAG, "setUploadProgressListener isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
}
}).getAsOkHttpResponse(new OkHttpResponseListener() {
@Override
public void onResponse(Response response) {
if (response != null) {
if (response.isSuccessful()) {
Log.d(TAG, "response is successful");
try {
Log.d(TAG, "response : " + response.body().source().readUtf8());
} catch (IOException e) {
e.printStackTrace();
}
} else {
Log.d(TAG, "response is not successful");
}
} else {
Log.d(TAG, "response is null");
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
}
use of com.androidnetworking.interfaces.OkHttpResponseListener in project Fast-Android-Networking by amitshekhariitbhu.
the class OkHttpResponseTestActivity method checkOkHttpResponse.
public void checkOkHttpResponse(View view) {
AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY).addPathParameter("pageNumber", "0").addQueryParameter("limit", "3").setTag(this).setPriority(Priority.LOW).build().setAnalyticsListener(new AnalyticsListener() {
@Override
public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
Log.d(TAG, " bytesSent : " + bytesSent);
Log.d(TAG, " bytesReceived : " + bytesReceived);
Log.d(TAG, " isFromCache : " + isFromCache);
}
}).getAsOkHttpResponse(new OkHttpResponseListener() {
@Override
public void onResponse(Response response) {
if (response != null) {
if (response.isSuccessful()) {
Log.d(TAG, "response is successful");
try {
Log.d(TAG, "response : " + response.body().source().readUtf8());
} catch (IOException e) {
e.printStackTrace();
}
} else {
Log.d(TAG, "response is not successful");
}
} else {
Log.d(TAG, "response is null");
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER).addBodyParameter("firstname", "Suman").addBodyParameter("lastname", "Shekhar").setTag(this).setPriority(Priority.LOW).build().setAnalyticsListener(new AnalyticsListener() {
@Override
public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
Log.d(TAG, " bytesSent : " + bytesSent);
Log.d(TAG, " bytesReceived : " + bytesReceived);
Log.d(TAG, " isFromCache : " + isFromCache);
}
}).getAsOkHttpResponse(new OkHttpResponseListener() {
@Override
public void onResponse(Response response) {
if (response != null) {
if (response.isSuccessful()) {
Log.d(TAG, "response is successful");
try {
Log.d(TAG, "response : " + response.body().source().readUtf8());
} catch (IOException e) {
e.printStackTrace();
}
} else {
Log.d(TAG, "response is not successful");
}
} else {
Log.d(TAG, "response is null");
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
AndroidNetworking.upload(ApiEndPoint.BASE_URL + ApiEndPoint.UPLOAD_IMAGE).setPriority(Priority.MEDIUM).addMultipartFile("image", new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "test.png")).setTag(this).build().setAnalyticsListener(new AnalyticsListener() {
@Override
public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
Log.d(TAG, " bytesSent : " + bytesSent);
Log.d(TAG, " bytesReceived : " + bytesReceived);
Log.d(TAG, " isFromCache : " + isFromCache);
}
}).setUploadProgressListener(new UploadProgressListener() {
@Override
public void onProgress(long bytesUploaded, long totalBytes) {
Log.d(TAG, "bytesUploaded : " + bytesUploaded + " totalBytes : " + totalBytes);
Log.d(TAG, "setUploadProgressListener isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
}
}).getAsOkHttpResponse(new OkHttpResponseListener() {
@Override
public void onResponse(Response response) {
if (response != null) {
if (response.isSuccessful()) {
Log.d(TAG, "response is successful");
try {
Log.d(TAG, "response : " + response.body().source().readUtf8());
} catch (IOException e) {
e.printStackTrace();
}
} else {
Log.d(TAG, "response is not successful");
}
} else {
Log.d(TAG, "response is null");
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
}
Aggregations