admin
2022-01-07 8dfe5354073b700af45d5cb472dd5f003e6f3f25
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
package com.ysvideo.zhibo.lib.common.util;
 
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.view.WindowManager;
 
public class SystemCommon {
 
    /**
     * 获取当前APP 版本号
     *
     * @param activity
     * @return
     */
    public static int getVersonCode(Context activity) {
        int versionCode = 1;
        try {
            versionCode = activity.getPackageManager().getPackageInfo(
                    activity.getPackageName(),
                    PackageManager.GET_CONFIGURATIONS).versionCode;// 获取app版本号
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionCode;
    }
 
    /**
     * 获取屏幕宽度
     *
     * @param activity
     * @return
     */
    public static float getScreenWidth(Context activity) {
        WindowManager wm = (WindowManager) activity
                .getSystemService(Context.WINDOW_SERVICE);
 
        return wm.getDefaultDisplay().getWidth();
    }
 
    /**
     * 获取屏幕高度
     *
     * @param activity
     * @return
     */
    public static float getScreenHeight(Context activity) {
        WindowManager wm = (WindowManager) activity
                .getSystemService(Context.WINDOW_SERVICE);
 
        return wm.getDefaultDisplay().getHeight();
    }
}