首页 > 解决方案 > 如何每 10 分钟向改造服务器发送一次发布请求?

问题描述

我真的需要帮助!我有一台服务器可以向我发送预测时间。我需要每 10 分钟向服务器发送一次请求(即使应用程序关闭)并询问当前时间。如果时间改变,我需要通知客户。停止触发器是预测时间是否是现在。

所以-我有 ClientActivity并且我有与服务器通信的代码。

我怎样才能做到这一点?

非常感谢!

public interface APIClient {

    @POST("/api/post_some_data")
    Call<PostResponse> getPostRequest(@Body PostRequest  body);

}

public class NetworkClient {

        public static final String BASE_URL = "http://*****:8080";
        public static Retrofit retrofit;
        /*
        This public static method will return Retrofit client
        anywhere in the appplication
        */
        public static Retrofit getRetrofitClient() {
            //If condition to ensure we don't create multiple retrofit instances in a single application
            if (retrofit == null) {
                //Defining the Retrofit using Builder
                retrofit = new Retrofit.Builder()
                        .baseUrl(BASE_URL) //This is the only mandatory call on Builder object.
                        .addConverterFactory(GsonConverterFactory.create()) // Convertor library used to convert response into POJO
                        .build();
            }
            return retrofit;
        }
    }

标签: javaandroidretrofit

解决方案


推荐阅读