• 获取设备信息


    public class DeviceUtil {
    
        /**
         * 是否有网
         * @param context
         * @return
         */
        public static boolean isNetworkConnected(Context context) {
            if (context != null) {
                ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                        .getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
                if (mNetworkInfo != null) {
                    return mNetworkInfo.isAvailable();
                }
            }
            return false;
        }
    
        /**
         * 返回版本名字
         * 对应build.gradle中的versionName
         * @param context
         * @return
         */
        public static String getVersionName(Context context) {
            String versionName = "";
            try {
                PackageManager packageManager = context.getPackageManager();
                PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
                versionName = packInfo.versionName;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return versionName;
        }
    
        /**
         * 返回版本号
         * 对应build.gradle中的versionCode
         * @param context
         * @return
         */
        public static String getVersionCode(Context context) {
            String versionCode = "";
            try {
                PackageManager packageManager = context.getPackageManager();
                PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
                versionCode = String.valueOf(packInfo.versionCode);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return versionCode;
        }
    
        /**
         * 获取手机品牌
         *
         * @return
         */
        public static String getPhoneBrand() {
            return android.os.Build.BRAND;
        }
    
        /**
         * 获取手机型号
         *
         * @return
         */
        public static String getPhoneModel() {
            return android.os.Build.MODEL;
        }
    
        /**
         * 获取手机Android 版本(4.4、5.0、5.1 ...)
         * @return
         */
        public static String getBuildVersion() {
            return android.os.Build.VERSION.RELEASE;
        }
    
        /**
         * 获取AndroidManifest.xml里 的值
         * @param context
         * @param name
         * @return
         */
        public static String getMetaData(Context context, String name) {
            String value = null;
            try {
                ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
                value = appInfo.metaData.getString(name);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
            return value;
        }
    
        public static String getAndroidId(Context context) {
            String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
            return androidId;
        }
    
        public static String getAndroidSerial() {
            String serialNum = Build.SERIAL;
            return serialNum;
        }
    
        public static String getAndroidInfo(Context context) {
            return String.format("品牌:%s,型号:%s,版本:%s,Id:%s,序列:%s,Mac:%s",getPhoneBrand(),
                                    getPhoneModel(),
                                    getBuildVersion(),
                                    getAndroidId(context),
                                    getAndroidSerial(),
                                    DeviceMacUtil.getMacFromHardware(context));
        }
    }
  • 相关阅读:
    quratz数据存储
    quratz线程
    scheduler 基本原理
    一致性哈希算法
    高并发流量控制
    049 DSL语句
    048 SparkSQL自定义UDAF函数
    047 SparkSQL自定义UDF函数
    Quratz的理解
    046 SparlSQL中的函数
  • 原文地址:https://www.cnblogs.com/matd/p/12855886.html
Copyright © 2020-2023  润新知