以下内容来自多个开源项目的整理和自己的项目积累
1.收集设备信息,用于信息统计分析
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 |
public static Properties collectDeviceInfo(Context context) { Properties mDeviceCrashInfo = new Properties(); try { PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES); if (pi != null) { mDeviceCrashInfo.put(VERSION_NAME, pi.versionName == null ? "not set" : pi.versionName); mDeviceCrashInfo.put(VERSION_CODE, pi.versionCode); } } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Error while collect package info", e); } Field[] fields = Build.class.getDeclaredFields(); for (Field field : fields) { try { field.setAccessible(true); mDeviceCrashInfo.put(field.getName(), field.get(null)); } catch (Exception e) { Log.e(TAG, "Error while collect crash info", e); } } return mDeviceCrashInfo; } public static String collectDeviceInfoStr(Context context) { Properties prop = collectDeviceInfo(context); Set deviceInfos = prop.keySet(); StringBuilder deviceInfoStr = new StringBuilder("{\n"); for (Iterator iter = deviceInfos.iterator(); iter.hasNext();) { Object item = iter.next(); deviceInfoStr.append("\t\t\t" + item + ":" + prop.get(item) + ", \n"); } deviceInfoStr.append("}"); return deviceInfoStr.toString(); } |
2.是否有SD卡
1 2 3 4 |
public static boolean haveSDCard() { return android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED); } |
3.动态隐藏软键盘
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
@TargetApi-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-always" style=" margin-top: 12px; margin-bottom: 12px; font-size: 13px !important; line-height: 15px !important;">
2.是否有SD卡
3.动态隐藏软键盘
|