From 6b31432e09efbb73f0ebb0747d8eef0d7747d66b Mon Sep 17 00:00:00 2001 From: Amin Bahrami Date: Thu, 4 Apr 2019 22:48:39 +0430 Subject: [PATCH] Change OkHttp to 3.12 to work on under 21 android versions --- ABPWebService/build.gradle | 2 +- .../abpwebservice/ABPWebService.java | 23 +++++++++---------- .../abpwebservicelib/ActivityMain.java | 3 ++- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ABPWebService/build.gradle b/ABPWebService/build.gradle index e2758d4..430bc00 100644 --- a/ABPWebService/build.gradle +++ b/ABPWebService/build.gradle @@ -29,5 +29,5 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "com.squareup.okhttp3:okhttp:3.14.0" + implementation "com.squareup.okhttp3:okhttp:3.12.0" } diff --git a/ABPWebService/src/main/java/com/aminbahrami/abpwebservice/ABPWebService.java b/ABPWebService/src/main/java/com/aminbahrami/abpwebservice/ABPWebService.java index f56f616..9483c30 100644 --- a/ABPWebService/src/main/java/com/aminbahrami/abpwebservice/ABPWebService.java +++ b/ABPWebService/src/main/java/com/aminbahrami/abpwebservice/ABPWebService.java @@ -117,20 +117,19 @@ public void writeTo(BufferedSink sink) throws IOException }; } - - OkHttpClient client=new OkHttpClient.Builder() - .connectTimeout(connectTimeout,TimeUnit.MILLISECONDS) - .readTimeout(readTimeout,TimeUnit.MILLISECONDS) - .writeTimeout(readTimeout,TimeUnit.MILLISECONDS) - .build(); - - Request request=new Request.Builder() - .url(url) - .post(requestBody) - .build(); - try { + OkHttpClient client=new OkHttpClient.Builder() + .connectTimeout(connectTimeout,TimeUnit.MILLISECONDS) + .readTimeout(readTimeout,TimeUnit.MILLISECONDS) + .writeTimeout(readTimeout,TimeUnit.MILLISECONDS) + .build(); + + Request request=new Request.Builder() + .url(url) + .post(requestBody) + .build(); + client.newCall(request).enqueue(new Callback() { @Override diff --git a/app/src/main/java/com/aminbahrami/abpwebservicelib/ActivityMain.java b/app/src/main/java/com/aminbahrami/abpwebservicelib/ActivityMain.java index fdeb06c..0a3825b 100644 --- a/app/src/main/java/com/aminbahrami/abpwebservicelib/ActivityMain.java +++ b/app/src/main/java/com/aminbahrami/abpwebservicelib/ActivityMain.java @@ -37,7 +37,8 @@ public void onClick(View view) private void sendRequest() { ABPWebService abpWebService=new ABPWebService(); - abpWebService.setUrl("https://14bazikon.com/api/users/login"); + //abpWebService.setUrl("https://14bazikon.com/api/users/login"); + abpWebService.setUrl("http://api.apiservice.info/"); //abpWebService.setUrl("https://api.github.com/repos/square/okhttp/issues"); //Check Permission in the feature