手机系统信息

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 "";
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

snpmyn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值