Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.kontakti;
- import okhttp3.OkHttpClient;
- import retrofit2.Call;
- import retrofit2.Response;
- import retrofit2.Retrofit;
- import retrofit2.converter.gson.GsonConverterFactory;
- public interface ContactServerCommunication {
- public interface ShowMessage{
- public void Message(String message);
- }
- public default void APICallInsert(ContactAPI.contacts contact, ShowMessage message){
- Thread t = new Thread(()->{
- try{
- OkHttpClient client = new OkHttpClient.Builder().build();
- Retrofit retrofit =
- new Retrofit.Builder()
- .baseUrl("http://10.0.0.13:4041")
- .addConverterFactory(
- GsonConverterFactory.create()
- )
- .client(client)
- .build();
- ContactAPI api = retrofit.create(ContactAPI.class);
- Call<ContactAPI.contacts> insertedUser = api.api_add_user(contact);
- Response<ContactAPI.contacts> r = insertedUser.execute();
- if(r.isSuccessful()){
- ContactAPI.contacts resp =r.body();
- message.Message("INSERTED IN SERVER WITH ID = "+resp.ID);
- }
- }catch (Exception e){
- message.Message("ERROR FROM SERVER: "+e.getLocalizedMessage());
- }
- });
- t.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement