Android Okhttp -定义常量和初始化对象

释放双眼,带上耳机,听听看~!
   //创建队列,用于异步调用
private Request request;
//线程阻塞方式调用
private Response response;
//访问对象
private Call call;
//okhttp实例
private OkHttpClient mOkHttpClient;
//线程阻塞方式请求的get,post状态码
private final static int GET_INSTANCE = 0;
private final static int POST_INSTANCE = 1;
//默认超时时间
private final static int VALUE_DEFAULT_TIME_OUT = 20 * 1000;
/**
* 参数类型
* "text", 文本
* "image", 图片
* "audio",音频
* "video",视频
* "object",其他
*/
private static final MediaType MEDIA_TYPE_TEXT = MediaType.parse("text/x-markdown; charset=utf-8");
private static final MediaType MEDIA_TYPE_JPG = MediaType.parse("image/png");
private static final MediaType MEDIA_TYPE_AUDIO = MediaType.parse("audio/mp3");
private static final MediaType MEDIA_TYPE_VIDEO = MediaType.parse("video/mp4");
private static final MediaType MEDIA_TYPE_OBJECT = MediaType.parse("application/octet-stream");
private static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
//给每个网络请求的标记
public static final String TAG_DATA = "tag_data";
public static final String TAG_IMAGE = "tag_image";
public static final String TAG_FILE = "tag_file";
private RequestHandle() {
//创建okHttpClient对象
mOkHttpClient = new OkHttpClient();
mOkHttpClient.setConnectTimeout(VALUE_DEFAULT_TIME_OUT, TimeUnit.MILLISECONDS);//连接超时
mOkHttpClient.setReadTimeout(VALUE_DEFAULT_TIME_OUT, TimeUnit.MILLISECONDS);//读取超时
mOkHttpClient.setWriteTimeout(VALUE_DEFAULT_TIME_OUT, TimeUnit.MILLISECONDS);//写入超时
}

 

人已赞赏
Android文章

android之如何在两个activity之间传递handler_利用broadcast广播机制

2020-4-26 10:48:02

Android文章

Android多个Activity相互跳转问题

2020-4-26 12:03:02

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索