Search in sources :

Example 1 with IGlobalResponseHandler

use of com.prajna.dtboy.http.IGlobalResponseHandler in project android-sex-http by dtboy1995.

the class MainActivity method init.

// 注册该接收者
void init() {
    // init the global cache
    HTTPUtil.initHttpCache(this);
    HTTPUtil.BASE_URL = "http://apistage.wenanle.com";
    HTTPUtil.globalResponseHandler = new IGlobalResponseHandler() {

        @Override
        public void disconnected(Context context) {
            Toast.makeText(context, "no networking!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void fail(String response, Context context) {
            Toast.makeText(context, "error happened!", Toast.LENGTH_SHORT).show();
        }
    };
    HTTPUtil.globalRequestHandler = new IGlobalRequestHandler() {

        @Override
        public List<Header> addHeaders() {
            List<Header> headers = new ArrayList<>();
            headers.add(new BasicHeader("version", "1.0.2"));
            // add ...
            return headers;
        }
    };
}
Also used : Context(android.content.Context) IGlobalRequestHandler(com.prajna.dtboy.http.IGlobalRequestHandler) ArrayList(java.util.ArrayList) List(java.util.List) IGlobalResponseHandler(com.prajna.dtboy.http.IGlobalResponseHandler) BasicHeader(cz.msebera.android.httpclient.message.BasicHeader)

Aggregations

Context (android.content.Context)1 IGlobalRequestHandler (com.prajna.dtboy.http.IGlobalRequestHandler)1 IGlobalResponseHandler (com.prajna.dtboy.http.IGlobalResponseHandler)1 BasicHeader (cz.msebera.android.httpclient.message.BasicHeader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1