/** 获取指定路径的apk的资源 */ @SuppressWarnings({"rawtypes", "unchecked"}) public static Resources getAPKResources(String apkPath) throws Exception { Context context = UIUtils.getContext(); if (null == context) { return null; } String PathAssetManager = "android.content.res.AssetManager"; Class assetMagCls = Class.forName(PathAssetManager); Constructor assetMagCt = assetMagCls.getConstructor((Class[]) null); Object assetMag = assetMagCt.newInstance((Object[]) null); Class[] typeArgs = new Class[1]; typeArgs[0] = String.class; Method assetMagAddAssetPathMtd = assetMagCls.getDeclaredMethod("addAssetPath", typeArgs); Object[] valueArgs = new Object[1]; valueArgs[0] = apkPath; assetMagAddAssetPathMtd.invoke(assetMag, valueArgs); Resources res = context.getResources(); typeArgs = new Class[3]; typeArgs[0] = assetMag.getClass(); typeArgs[1] = res.getDisplayMetrics().getClass(); typeArgs[2] = res.getConfiguration().getClass(); Constructor resCt = Resources.class.getConstructor(typeArgs); valueArgs = new Object[3]; valueArgs[0] = assetMag; valueArgs[1] = res.getDisplayMetrics(); valueArgs[2] = res.getConfiguration(); res = (Resources) resCt.newInstance(valueArgs); return res; }
/** 获得设备的纵向dpi */ public static float getHeightDpi() { Context context = UIUtils.getContext(); if (null == context) { return 0; } DisplayMetrics dm = new DisplayMetrics(); dm = context.getApplicationContext().getResources().getDisplayMetrics(); return dm.ydpi; }
/** 获取单个应用最大分配内存,单位为byte */ public static long getOneAppMaxMemory() { Context context = UIUtils.getContext(); if (context == null) { return -1; } ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); return activityManager.getMemoryClass() * 1024 * 1024; }
/** * 得到屏幕的高度 * * @param mContext * @return */ public static int getScreenHeight() { Context context = UIUtils.getContext(); if (null == context) { return 0; } DisplayMetrics dm = new DisplayMetrics(); dm = context.getApplicationContext().getResources().getDisplayMetrics(); return dm.heightPixels; }
/** 检测手机是否已插入SIM卡 */ public static boolean isCheckSimCardAvailable() { Context context = UIUtils.getContext(); if (null == context) { return false; } final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return tm.getSimState() == TelephonyManager.SIM_STATE_READY; }
/** 获取系统中的Library包 */ public static List<String> getSystemLibs() { Context context = UIUtils.getContext(); if (null == context) { return null; } PackageManager pm = context.getPackageManager(); String[] libNames = pm.getSystemSharedLibraryNames(); List<String> listLibNames = Arrays.asList(libNames); LogUtils.d("SystemLibs: " + listLibNames); return listLibNames; }
/** 手机低内存运行阀值,单位为byte */ public static long getThresholdMemory() { Context context = UIUtils.getContext(); if (context == null) { return -1; } ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(info); return info.threshold; }
/** 返回本地手机号码,这个号码不一定能获取到 */ public static String getNativePhoneNumber() { Context context = UIUtils.getContext(); if (null == context) { return null; } TelephonyManager telephonyManager; telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String NativePhoneNumber = null; NativePhoneNumber = telephonyManager.getLine1Number(); return NativePhoneNumber; }
/** 手机是否处于低内存运行 */ public static boolean isLowMemory() { Context context = UIUtils.getContext(); if (context == null) { return false; } ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(info); return info.lowMemory; }
/** 获取屏幕的分辨率 */ @SuppressWarnings("deprecation") public static int[] getResolution() { Context context = UIUtils.getContext(); if (null == context) { return null; } WindowManager windowMgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); int[] res = new int[2]; res[0] = windowMgr.getDefaultDisplay().getWidth(); res[1] = windowMgr.getDefaultDisplay().getHeight(); return res; }
/** sim卡是否可读 */ public static boolean isCanUseSim() { Context context = UIUtils.getContext(); if (null == context) { return false; } try { TelephonyManager mgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return TelephonyManager.SIM_STATE_READY == mgr.getSimState(); } catch (Exception e) { LogUtils.e(e); } return false; }
/** 取得当前sim手机卡的imsi */ public static String getIMSI() { Context context = UIUtils.getContext(); if (null == context) { return null; } String imsi = null; try { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); imsi = tm.getSubscriberId(); } catch (Exception e) { LogUtils.e(e); } return imsi; }
/** 获取当前设备的SN */ public static String getSimSN() { Context context = UIUtils.getContext(); if (null == context) { return null; } String simSN = null; try { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); simSN = tm.getSimSerialNumber(); } catch (Exception e) { LogUtils.e(e); } return simSN; }
/** 判断是否是第三方软件 */ public static boolean isThirdPartyApp(String packageName) { Context context = UIUtils.getContext(); if (null == context) { return false; } PackageManager pm = context.getPackageManager(); PackageInfo packageInfo; try { packageInfo = pm.getPackageInfo(packageName, 0); return isThirdPartyApp(packageInfo); } catch (PackageManager.NameNotFoundException e) { Logger.i(e.toString()); return false; } }
/** 获取当前设备的MAC地址 */ public static String getMacAddress() { Context context = UIUtils.getContext(); if (null == context) { return null; } String mac = null; try { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wm.getConnectionInfo(); mac = info.getMacAddress(); } catch (Exception e) { LogUtils.e(e); } return mac; }
/** 根据packageName获取packageInfo */ public static PackageInfo getPackageInfo(String packageName) { Context context = UIUtils.getContext(); if (null == context) { return null; } if (StringUtils.isEmpty(packageName)) { packageName = context.getPackageName(); } PackageInfo info = null; PackageManager manager = context.getPackageManager(); // 根据packageName获取packageInfo try { info = manager.getPackageInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); } catch (PackageManager.NameNotFoundException e) { Logger.i(e.toString()); } return info; }
/** 通过包名读取已安装APP数字签名 */ public static String getInstalledPackageSignature(String packageName) { Context context = UIUtils.getContext(); if (null == context) { return null; } String signature = null; try { PackageManager pm = context.getPackageManager(); ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_SIGNATURES); String apkPath = appInfo.sourceDir; signature = getJarSignature(apkPath); } catch (PackageManager.NameNotFoundException e) { Logger.i(e.toString()); } catch (Exception e) { Logger.i(e.toString()); } return signature; }
/** 获得设备的横向dpi */ public static float getWidthDpi() { Context context = UIUtils.getContext(); if (null == context) { return 0; } DisplayMetrics dm = null; try { if (context != null) { dm = new DisplayMetrics(); dm = context.getApplicationContext().getResources().getDisplayMetrics(); } return dm.densityDpi; } catch (Exception e) { e.printStackTrace(); } return 0; }
/** 获取指定包名应用占用的内存,单位为byte */ public static long getUsedMemory(String packageName) { Context context = UIUtils.getContext(); if (context == null) { return -1; } if (StringUtils.isEmpty(packageName)) { packageName = context.getPackageName(); } long size = 0; ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> runapps = activityManager.getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo runapp : runapps) { // 遍历运行中的程序 if (packageName.equals(runapp.processName)) { // 得到程序进程名,进程名一般就是包名,但有些程序的进程名并不对应一个包名 // 返回指定PID程序的内存信息,可以传递多个PID,返回的也是数组型的信息 Debug.MemoryInfo[] processMemoryInfo = activityManager.getProcessMemoryInfo(new int[] {runapp.pid}); // 得到内存信息中已使用的内存,单位是K size = processMemoryInfo[0].getTotalPrivateDirty() * 1024; } } return size; }
/** * 获取应用的包名 * * @return */ public static String getPackageName() { return UIUtils.getContext().getPackageName(); }
public static void display(View view, String uri) { if (utils == null) { utils = new BitmapUtils(UIUtils.getContext()); } utils.display(view, uri); }