Retrofit的简单使用
来源:互联网 发布:手机系统检测软件 编辑:程序博客网 时间:2024/06/01 10:28
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'//Retrofit1所需要的包compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'//ConverterFactory的Gson依赖包
package com.example.retrofitdemo;import retrofit2.Call;import retrofit2.http.GET;import retrofit2.http.POST;import retrofit2.http.Query;/** * Created by xsj on 2017/12/1. */public interface demo { //get请求 @GET("ad/getAd") Call<ShopBean> getCall(); @POST("user/login") Call<UserBean> postCall(@Query("mobile") String mo, @Query("password") String dd);}
Retrofit build = new Retrofit.Builder() .baseUrl("http://120.27.23.105/") .addConverterFactory(GsonConverterFactory.create()) .build();demo demo = build.create(demo.class);Call<UserBean> userBeanCall = demo.postCall("15340986701", "123456");
package com.example.wuxiruionetext.Utils;import android.content.Context;import android.net.ConnectivityManager;import android.net.NetworkInfo;/** * Created by xsj on 2017/12/2. */public class NetUils { private static volatile NetUils instance; private Context context; private NetUils(Context context) { this.context = context; } public static NetUils getInstance(Context context) { if (instance == null) { synchronized (NetUils.class) { if (instance == null) { instance = new NetUils(context); } } } return instance; } public int getNetype() { int netType = -1; ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); //无网络 if (networkInfo == null) { return netType; } int nType = networkInfo.getType(); //手机网络 if (nType == ConnectivityManager.TYPE_MOBILE) { netType = 2; } else if (nType == ConnectivityManager.TYPE_WIFI) {//wifi网络 netType = 1; } //返回 return netType; }}
阅读全文
0 0
- Retrofit的简单使用
- Retrofit的简单使用
- Retrofit的简单使用
- Retrofit的简单使用
- Retrofit的简单使用
- Retrofit的简单使用
- Retrofit的简单使用
- Retrofit的简单使用
- Retrofit的简单使用
- Retrofit的简单使用
- retrofit的简单使用
- retrofit的简单使用
- Retrofit 的简单使用
- Retrofit的简单使用
- Retrofit的简单使用
- Retrofit的简单使用
- Retrofit的简单使用
- Retrofit的简单使用
- 自定义view轮播图
- 20171202小Dome
- json--1.概述
- ButterKnife的使用详解
- 简单自定义viewpager,小圆点控件
- Retrofit的简单使用
- GreenDao简单操作
- 题库错题簿1—10
- shiro 框架之拦截器机制
- 题库错题簿11—30
- shiro框架之JSP标签
- 如何快速实现高并发短文检索
- shiro框架之会话管理
- 今天写自定一轮播图