DeviceUtil.java 源代码


package com.x8zs.plugin.utils;

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

public class DeviceUtil {
    public static String getImei(Context context) {
        try {
            String deviceId = ((TelephonyManager) context.getSystemService("phone")).getDeviceId();
            if (deviceId == null) {
                return "";
            }
            return deviceId;
        } catch (Throwable unused) {
            return "";
        }
    }

    public static String getImsi(Context context) {
        try {
            String subscriberId = ((TelephonyManager) context.getSystemService("phone")).getSubscriberId();
            if (subscriberId == null) {
                return "";
            }
            return subscriberId;
        } catch (Throwable unused) {
            return "";
        }
    }

    public static String getWifiMac(Context context) {
        try {
            String macAddress = ((WifiManager) context.getSystemService(com.efs.sdk.base.core.util.NetworkUtil.NETWORK_TYPE_WIFI)).getConnectionInfo().getMacAddress();
            if (macAddress == null) {
                return "";
            }
            return macAddress;
        } catch (Throwable unused) {
            return "";
        }
    }
}