Posts

Showing posts with the label retrofit2

I am not able to use RestApi in android application

Image
Clash Royale CLAN TAG #URR8PPP I am not able to use RestApi in android application Here is my RestApi get call result RestApi An in my android application i am using the retrofit library to call this api to show items in my android application, here is the api call in android package com.aditmsolutions.www.foodie; import java.util.List; import retrofit2.Call; import retrofit2.http.GET; public interface Api { String BASE_URL = "https://10.0.2.2:51087/api/"; @GET("items") Call<List<Item>> getItems(); } When I run my app it gives this error message "HandShake failed" error Please help And here is logcat view And her is the code to getItems private void getItems() { Retrofit retrofit = new Retrofit.Builder() .baseUrl(Api.BASE_URL) .addConverterFactory(GsonConverterFactory.create()) //Here we are using the GsonConverterFactory to directly convert json data to object .build(); Api api = ret...

How to make MultipartBbody.Part request from cache image using retrofit

Image
Clash Royale CLAN TAG #URR8PPP How to make MultipartBbody.Part request from cache image using retrofit My image is cached at located: file:///data/user/0/com.example.muhammadusman.project/cache/cropped1340954678061130725.jpg how can i make the Multipart.body request for this interface: @Multipart @POST("/image/{name}") Call<Recognition> recognizeImage( @Path("name")String name, @Part MultipartBody.Part image); Input to the Function key="40" imageName="cropped1340954678061130725.jpg" path="file:///data/user/0/com.example.muhammadusman.project/cache/cropped1340954678061130725.jpg" This is My Code: i am using this code to make the MultipartBody.Part object. But i am not able to make the object. Always program crash. public static MultipartBody.Part creatPartFromPath(String key,String imageName,String path){ File file=new File(path); String mediaType= getMimeType(path); Reques...

How do I post a json array with retrofit2? For example,

Image
Clash Royale CLAN TAG #URR8PPP How do I post a json array with retrofit2? For example, i have similar issue, API require to send like this checkpoin=[{"id":"1907","gps":"31213123,3131231","status":"1"}] I successfully created: [{"id":"1907","gps":"31213123,3131231","status":"1"}] and retrofit configs are like this @POST("save_clockings")Observable<ResponseSaveCehckpoint> saveChekpoint ( @Query(value = "checkpoint" ,encoded = true) List<JsonObject> checkpoint); but i look with HTTP logging URL like this https://my.domain.com/api/save_clockings?checkpoint={%22id%22:%221907%22,%22gps%22:%2231213123,3131231%22,%22time%22:%221532674384157%22,%22status%22:%221%22} i send via insomnia that's success, enter image description here why retrofit convert character (") to (%22); can someone help me? Thanks ...