Retrofit的简单使用

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;
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值