panlili2024
2024-09-19 071a8328823a2861f93ce556a4da3e4119cab1a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.hdl.sdk.ttl_sdk.utlis;
 
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
 
import java.math.BigDecimal;
 
/**
 * Created by JLChen on 2019/7/4
 */
public class HDLUtlis {
 
    public static final String REMAEK_NULL = "\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5\uF8F5";
    /**
     * 将object转为Integer类型
     * @param object
     * @return
     */
    public static Integer getIntegerByObject(Object object){
        Integer in = null;
        if(object!=null){
            if(object instanceof Integer){
                in = (Integer)object;
            }else if(object instanceof String){
                in = Integer.parseInt((String)object);
            }else if(object instanceof Double){
                in = (int)((double)object);
            }else if(object instanceof Float){
                in = (int)((float)object);
            }else if(object instanceof BigDecimal){
                in = ((BigDecimal)object).intValue();
            }else if(object instanceof Long){
                in = ((Long)object).intValue();
            }
        }
        return in;
    }
 
    /**
     * getColor
     * @param context
     * @param color
     * @return
     */
    public static int getColor(Context context, int color) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            return context.getColor(color);
        } else {
            return context.getResources().getColor(color);
        }
    }
 
    /**
     * int类型转4字节byte数组
     * @param mInt
     * @return 4字节byte数组
     */
    public static byte[] intToByteArray(int mInt) {
        byte[] result = new byte[4];
        // 由高位到低位
        result[0] = (byte) ((mInt >> 24) & 0xFF);
        result[1] = (byte) ((mInt >> 16) & 0xFF);
        result[2] = (byte) ((mInt >> 8) & 0xFF);
        result[3] = (byte) (mInt & 0xFF);
        return result;
    }
 
    public static boolean checkIsBinFile(String path){
        try {
            String prefix = path.substring(path.lastIndexOf(".") + 1).toUpperCase();
            if (!prefix.equals("BIN")) {
                return false;
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    }
 
 
    /**
     * 获取版本号
     *
     * @param context 上下文
     *
     * @return 版本号
     */
    public static int getVersionCode(Context context) {
 
        //获取包管理器
        PackageManager pm = context.getPackageManager();
        //获取包信息
        try {
            PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
            //返回版本号
            return packageInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
 
        return 0;
 
    }
 
}