手机系统信息

package util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.provider.Settings;
import android.telephony.TelephonyManager;

import java.util.Locale;

/**
 * Created on 2018/6/20.
 *
 * @desc 系统
 */
public class SystemUtils {
    /**
     * 系统语言
     *
     * @return 【中文-中国】返【zh-CN】
     */
    public static String getPhoneSystemLanguage() {
        return Locale.getDefault().getLanguage();
    }

    /**
     * 系统语言列表(Locale列表)
     *
     * @return 语言列表
     */
    public static Locale[] getPhoneSystemLanguageList() {
        return Locale.getAvailableLocales();
    }

    /**
     * 系统版本
     *
     * @return 系统版本
     */
    public static String getPhoneSystemVersion() {
        return android.os.Build.VERSION.RELEASE;
    }

    /**
     * 型号
     *
     * @return 型号
     */
    public static String getPhoneModel() {
        return android.os.Build.MODEL;
    }

    /**
     * 厂商
     *
     * @return 厂商
     */
    public static String getPhoneBrand() {
        return android.os.Build.BRAND;
    }

    /**
     * IMEI
     * 需<uses-permission android:name="android.permission.READ_PHONE_STATE" />
     *
     * @param context 上下文
     * @return IMEI
     */
    @SuppressLint("HardwareIds")
    public static String getPhoneIMEI(Context context) {
        try {
            // 实例化TelephonyManager对象
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            // IMEI
            String imei;
            if (telephonyManager.getDeviceId() != null) {
                imei = telephonyManager.getDeviceId();
            } else {
                // android.provider.Settings;
                imei = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
            }
            // 并非何时都能获得
            if (imei == null) {
                imei = "";
            }
            return imei;
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }

    }

    /**
     * IMSI
     *
     * @param context 上下文
     * @return IMSI
     */
    public static String getIMSI(Context context) {
        try {
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            // IMSI
            String imsi = telephonyManager.getSubscriberId();
            if (null == imsi) {
                imsi = "";
            }
            return imsi;
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
}

猜你喜欢

转载自blog.csdn.net/zsp_android_com/article/details/80752856