retrofit2

How to send Photos to server with additional fields in Android app?

若如初见. 提交于 2019-12-11 10:10:00
问题 I try to send multiple photos to server with Retrofit. I have endpoint like this: @Multipart @POST("/v1/props") Call<ModelProp> createProp( @Header("x-auth") String token, @Part List<MultipartBody.Part> photo ); But I don't know how to add to this POST method additional information with: int price; String currency; ArrayList<String> tags; Can someone help me add this fields to POST with retrofit? edit: Array may have 1000+ elements 回答1: In Retrofit 2, You can send it extra data with the image

How to get Retrofit callback get response body in Json formate

独自空忆成欢 提交于 2019-12-11 09:27:01
问题 I'm using Retrofit for integrating web services and when run my app controller going to Retrofit success block but how can i print ResponseBody in Json string formate can some one help me please Main Activity:- import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import java.util.concurrent.TimeUnit; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; @Override

Retrofit API call: How to make sure that value is not null after making api call?

耗尽温柔 提交于 2019-12-11 08:27:00
问题 I have below AuthenticationResponse model that I use for 3 api calls using retrofit2. If I make the verifyEmail call f.e. the JSON response body only contains an attribute for valid email (so something like {"validEmail": true} ). The other 2 calls only contain attributes for "resetSuccesful" or the other 4. How can I make sure/check that when I receive the response to the verifyEmail call f.e. that it contains a non null value for validEmail?? Service: interface AuthenticationService { @POST

Retrofit2: Upload an Image with some Form Data-Android

耗尽温柔 提交于 2019-12-11 07:56:01
问题 The above screenshot contain the Post method and Response from the server.. here i am trying to upload an image with some data to my server(catch the image from gallery or camera).. I am trying to achieve this via retrofit2. trying some methods from Internet... but i can't get the right way to done it new in retrofit2. so I cant done this. How to Create retrofit2 interface and handle the response.. please help Edit My Try Code in Activity ProofAPI service = retrofit.create(ProofAPI.class);

Add bearer token selectively to header in Retrofit

笑着哭i 提交于 2019-12-11 07:35:51
问题 I would like to know if there is any option to enable/disable header Interceptor based on a flag or annotation in Retrofit. Since there are few paths in my API that do not need a token, I need to skip adding token to those API calls. Currently I have a simple Interceptor which will add a header to all the requests that are made from my application //builder is of type OkHttpClient.Builder builder.addInterceptor(chain -> { Request request = chain.request().newBuilder(). addHeader(

Retrofit2 deserialization / conversion on non-main thread using rxjava

淺唱寂寞╮ 提交于 2019-12-11 07:35:02
问题 I've referred to this answer already and it seems to be related to Retrofit v1. Goal -> To reduce cold start time by making ObjectMapper work on non-main thread. This image shows a stack trace of it happening on the main thread. Setup: compile "com.squareup.retrofit2:retrofit:2.1.0" compile "com.squareup.retrofit2:converter-jackson:2.1.0" compile "com.squareup.retrofit2:adapter-rxjava:2.1.0" compile 'io.reactivex:rxjava:1.1.9' This is configuration for retrofit .addCallAdapterFactory

How to add http interceptor in retrofit in a service generator class

此生再无相见时 提交于 2019-12-11 07:20:13
问题 I created a separate service generator class as shown is this guide https://futurestud.io/tutorials/retrofit-2-manage-request-headers-in-okhttp-interceptor ApiServiceGenerator.java public class ApiServiceGenerator { private static final String BASE_URL = "http://192.168.0.205/hadia/api/"; private static Retrofit.Builder builder = new Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()); private static Retrofit retrofit = builder.build(); private static

Caching network calls using RxJava for some duration

不羁岁月 提交于 2019-12-11 07:06:27
问题 I am making a network using Retorfit + RxJava2 and I want to cache the response for 30 seconds. Any calls made after 30 seconds interval should get the latest results from server. I tried doing this using Replay operator but it still makes a network call every time I call subscribe. I am not an expert in RxJava so maybe my understanding of using Replay for caching like that is wrong. public Observable<Name> getName() { return retrofitBuilder.getName() .subscribeOn(Schedulers.io()) .replay(30,

Retrofit Android: how to fetch Json data using id and display into textview

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 06:55:54
问题 I want to fetch only particular data from json object using id and show it in textview. I am able fetch data in listview. But i want fetch data without using listview into basic textview. using each id. **Only want Fetch id="1" json data and display it into textview name,mobile,age,email. After clicking button ** Json Data { "details": [ { "age": "56", "email": "john@gmail.com", "id": "1", "mobile": "985323154", "name": "John" }, { "age": "0", "email": "", "id": "26", "mobile": "0", "name":

Request in Android always giving socket timeout exception

梦想与她 提交于 2019-12-11 06:35:02
问题 I'm trying to make two requests when user clicks on a button. However, the request might take a little while. When the user is on battery save mode and screens lock his device while the request is still being done, the request will not complete and will give a socket timeout exception. I made a sample project to try this out and you can find it here. I'm using retrofit and RxJava to make my requests like this: networkFactory.request() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers