package com.mints.library.utils;

import android.app.Application;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * 描述：获取手机参数信息
 * 作者：孟崔广
 * 时间：2018/1/10 17:51
 * 邮箱：mengcga@163.com
 */
public class PhoneParameterUtils {

    /**
     * 获取MAC地址
     *
     * @return
     */
    public static String getMacAddress(Application application) {
        WifiManager manager = (WifiManager) application.getSystemService(Context.WIFI_SERVICE);
        String MacAddress = "";
        if (manager != null) {
            MacAddress = manager.getConnectionInfo().getMacAddress();
        }
        return MacAddress;
    }

    /**
     * 返回用户手机运营商名称  * @param telephonyManager  * @return
     */
    public static String getProvidersName(Application loanApplication) {
        String ProvidersName = null;
        try {
            TelephonyManager telephonyManager = (TelephonyManager) loanApplication.getSystemService(Context.TELEPHONY_SERVICE);
            String IMSI; // 返回唯一的用户ID;就是这张卡的编号神马的
            IMSI = telephonyManager.getSubscriberId();
            if (IMSI == null)
                return "unkwon";
            // IMSI号前面3位460是国家，紧接着后面2位00 02是中国移动，01是中国联通，03是中国电信。其中
            if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
                ProvidersName = "中国移动";
            } else if (IMSI.startsWith("46001")) {
                ProvidersName = "中国联通";
            } else if (IMSI.startsWith("46003")) {
                ProvidersName = "中国电信";
            }
            ProvidersName = URLEncoder.encode("" + ProvidersName, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block     e.printStackTrace();
        }
        return ProvidersName;
    }

}
