retrofit

Login Example using Retrofit, MVVM, LiveData in android

有些话、适合烂在心里 提交于 2019-12-14 03:12:22
问题 I checked this article but observe the response changes in MainActivity. Here is my code for LoginRepo public MutableLiveData<LoginResponseModel> checkLogin(LoginRequestModel loginRequestModel) { final MutableLiveData<LoginResponseModel> data = new MutableLiveData<>(); Map<String, String> params = new HashMap<>(); params.put("email", loginRequestModel.getEmail()); params.put("password", loginRequestModel.getPassword()); apiService.checkLogin(params) .enqueue(new Callback<LoginResponseModel>()

RxJava retry based on logic

我的梦境 提交于 2019-12-14 00:21:50
问题 Here is the case, I have API call usign Retrofit that might fail due to network error. If it fails we will show error message with a retry button. When user presses the retry button we need to retry the latest Observable again. Possible Solutions: Retry: Retry should be used before subscribing to the observable and it will immediately resubscribe again if error happens and that is what I don't want, I need to resubscribe only if the user pressed the Retry button. RetryWhen: It Will keep

Why json_encode create new line after password_verify php and create error in android studio

点点圈 提交于 2019-12-13 22:24:11
问题 I'm new in php, now i want to create json_encode and use it as API to my android apps, but after i try it on android, the log say that Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ and the postman shows one line after the json response. how to eliminate the new line (line two) which is not contain anything. This is my response in postman: 1 {"kode":1,"pesan":"Login Berhasil"} 2 picture spoiler : https://imgur.com/a/fKi0a72 thank you for all your response afterwards i have

How to catch the Exception in Retrofit android

江枫思渺然 提交于 2019-12-13 20:30:46
问题 I have defined the classes as below. I have used dagger with Retrofit here What I am trying to do :: I am trying to catch the OfflineException in the request below how to catch it in Main Activity properly. RequestInterceptor.java public class RequestInterceptor implements Interceptor { ConnectivityManager connectivityManager; Application mApplication; @Inject public RequestInterceptor(Application mApplication) { this.mApplication = mApplication; connectivityManager = (ConnectivityManager)

Retrofit - add field dynamically during serialization

血红的双手。 提交于 2019-12-13 20:24:09
问题 I'm currently using Retrofit 2.3 in my Android project and recently the API we are using was updated so that it needs to have "version":number in JSON body in all POST requests. So let's say we need to pass UserCredentials object - previously body of the request was simply serialized using GSON converter and looked like this {"username":"myUsername", "password":"myPassword"} and now it has to have additional "version" field: {"username":"myUsername", "password":"myPassword", "version":1} I've

Android 知识梳理目录

左心房为你撑大大i 提交于 2019-12-13 20:00:23
一、Java 知识梳理 Java&Android 基础知识梳理(0) - Java 基础知识大纲 Java&Android 基础知识梳理(1) - 注解 Java&Android 基础知识梳理(2) - 序列化 Java&Android 基础知识梳理(3) - 内存区域 Java&Android 基础知识梳理(4) - 垃圾收集器与内存分配策略 Java&Android 基础知识梳理(5) - 类加载&对象实例化 Java&Android 基础知识梳理(6) - 字节输入输出流 Java&Android 基础知识梳理(7) - Android 虚拟机 Java&Android 基础知识梳理(8) - 容器类 Java&Android 基础知识梳理(9) - LruCache 源码解析 Java&Android 基础知识梳理(10) - SparseArray 源码解析 Java&Android 基础知识梳理(11) - 浅拷贝 Vs 深拷贝 Java&Android 基础知识梳理(12) - 泛型 Java&Android 基础知识梳理(13) - 反射 二、Android 基础知识 2.1 Activity 知识梳理 Activity 知识梳理(1) - Activity 生命周期 Activity 知识梳理(2) - Activity 栈 Activity 知识梳理(3) -

Can't read rss XML , with Simple XML and Retrofit

眉间皱痕 提交于 2019-12-13 19:54:43
问题 I have searched a lot, but I can't assign my XML with My Classes and I take an Error from Retrofit when I am trying to Deserialize the XML. This is the XML that I call from my Interface ( only the first Item): <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0

Retrofit SocketTimeoutException - Uploading Image

蹲街弑〆低调 提交于 2019-12-13 17:54:07
问题 I'm currently using Retrofit for Android as my network communications. When POSTing to my backend server an image, the server is in the middle of the upload and then retrofit "times out" with SocketTimeoutException. I have added the OKhttp library as some have suggested and still getting the timeout. The current img sizes are around 750kb because I have scaled them down. Is there an appropriate way to changes the amount of time until a timeout for retrofit? Or is there a better way to upload

Blocking request interceptor with Retrofit?

感情迁移 提交于 2019-12-13 14:27:10
问题 Is there a nice way to implement "blocking" request interceptor? The main idea is that all requests should be intercepted and added additional header - token . If token does not exist yet it should be retrieved first, then added to that request and cached for future used. token is retrieved via API call. I've tried to do synchronous request, but, that produces android.os.NetworkOnMainThreadException . And implementing with in_progress flags it doesn't look nice. 回答1: You can already do the

Caching with Retrofit 2.0 and okhttp3

笑着哭i 提交于 2019-12-13 12:22:10
问题 I'm trying to implement caching using Retrofit and OkHttp. Here what I've already done: private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() { @Override public Response intercept(Interceptor.Chain chain) throws IOException { Request originalRequest = chain.request(); Request.Builder request = originalRequest.newBuilder(); Response response = chain.proceed(request.build()); return response.newBuilder() .removeHeader("Pragma") .removeHeader("Cache-Control")