Blame view

src/com/ectrip/cyt/exceptionsave/info/ApplitionInfo.java 4.92 KB
3c2353cd   杜方   1、畅游通核销app源码提交;
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  package com.ectrip.cyt.exceptionsave.info;
  
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.content.Context;
  import android.content.pm.ApplicationInfo;
  import android.content.pm.PackageInfo;
  import android.content.pm.PackageManager;
  import android.content.pm.PackageManager.NameNotFoundException;
  import android.graphics.Rect;
  import android.provider.Settings.Secure;
  import android.util.DisplayMetrics;
  import android.util.Log;
  
  public class ApplitionInfo {
  
      /**
       * 获取状态栏
       *
       * @param context
       * @return
       */
      public static int getStatusHeight(Context context) {
          Rect frame = new Rect();
          if (context instanceof Activity) {
              ((Activity) context).getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
              return frame.top;
          }
          return 20;
      }
  
  //    /**
  //     * 获取屏幕高度
  //     *
  //     * @param context
  //     * @return
  //     */
  //    public static int getHeightPixels(Context context) {
  //        if (heightPixels == 0) {
  //            heightPixels = getDisPlayMetrics(context).heightPixels;
  //        }
  //        return heightPixels;
  //    }
  //
  //    /**
  //     * 获取屏幕分辨率
  //     *
  //     * @param context
  //     * @return
  //     */
  //    public static float getDensity(Context context) {
  //        if (density == 0) {
  //            if (metrics == null) {
  //                getDisPlayMetrics(context);
  //            }
  //            density = metrics.density;
  //        }
  //        return density;
  //    }
  //
  //
  //    /**
  //     * 获取
  //     *
  //     * @param context
  //     * @return
  //     */
  //    public static DisplayMetrics getDisPlayMetrics(Context context) {
  //        if (metrics == null) {
  //            metrics = new DisplayMetrics();
  //            if (context instanceof Activity) {
  //                ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
  //            }
  //        }
  //        return metrics;
  //    }
  
      /**
       * @return the ANDROID_ID that identify the device, or the "emulator" string
       * on the emulator.
       */
      public static String getAndroidId(Context context) {
          String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
          if (androidId == null || androidId.length() <= 0) {
              androidId = "emulator";
          }
          return androidId;
      }
      /**
       * @return the version name of the application
       */
      public static String getVersionName(Context context) {
          String versionName = "unknown version";
          try {
              android.content.pm.PackageManager packageMng = context.getPackageManager();
              if (packageMng != null) {
                  PackageInfo packageInfo = packageMng.getPackageInfo(context.getPackageName(), 0);
                  if (packageInfo != null) {
                      versionName = packageInfo.versionName;
                  }
              }
          } catch (PackageManager.NameNotFoundException e) {
          }
          return versionName;
      }
  
  
  
      /**
       * @return the version code of the application
       */
      public static int getVersionCode(Context context) {
          if (context == null) {
              return -1;
          }
          int versionCode = -1;
          try {
              PackageManager packageMng = context.getPackageManager();
              if (packageMng != null) {
                  PackageInfo packageInfo = packageMng.getPackageInfo(context.getPackageName(), 0);
                  if (packageInfo != null) {
                      versionCode = packageInfo.versionCode;
                  }
              }
          } catch (PackageManager.NameNotFoundException e) {
          }
  
          return versionCode;
      }
  
      /**
       * @return Android SDK, Version, Manufacturer, Model, Device
       */
      @SuppressLint("DefaultLocale")
      public static String getSDK() {
          return String.format("%d-%s", android.os.Build.VERSION.SDK_INT, android.os.Build.VERSION.RELEASE);
      }
  
      /**
       * @return true if the app is debuggable, false otherwise
       */
      public static boolean isDebuggable(Context context) {
          if (context == null) {
              return false;
          }
  
          ApplicationInfo appInfo = context.getApplicationInfo();
          if (appInfo != null) {
              return ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
          } else {
              return (ApplicationInfo.FLAG_DEBUGGABLE != 0);
          }
      }
  
  
      /**
       * @return true if this device has Amazon Market App installed
       */
      public static boolean hasAmazonMarketApp(Context context) {
          if (context == null) {
              return false;
          }
          try {
              PackageManager packageMng = context.getPackageManager();
              if (packageMng != null) {
                  return (null != packageMng.getPackageInfo("com.amazon.venezia", 0));
              }
              return false;
          } catch (NameNotFoundException e) {
              return false;
          }
      }
  }