Ejemplo n.º 1
0
 /** 获取指定路径的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;
 }
Ejemplo n.º 2
0
 /** 获得设备的纵向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;
 }
Ejemplo n.º 3
0
 /** 获取单个应用最大分配内存,单位为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;
 }
Ejemplo n.º 4
0
 /**
  * 得到屏幕的高度
  *
  * @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;
 }
Ejemplo n.º 5
0
 /** 检测手机是否已插入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;
 }
Ejemplo n.º 6
0
 /** 获取系统中的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;
 }
Ejemplo n.º 7
0
 /** 手机低内存运行阀值,单位为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;
 }
Ejemplo n.º 8
0
 /** 返回本地手机号码,这个号码不一定能获取到 */
 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;
 }
Ejemplo n.º 9
0
 /** 手机是否处于低内存运行 */
 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;
 }
Ejemplo n.º 10
0
 /** 获取屏幕的分辨率 */
 @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;
 }
Ejemplo n.º 11
0
 /** 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;
 }
Ejemplo n.º 12
0
 /** 取得当前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;
 }
Ejemplo n.º 13
0
 /** 获取当前设备的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;
 }
Ejemplo n.º 14
0
 /** 判断是否是第三方软件 */
 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;
   }
 }
Ejemplo n.º 15
0
 /** 获取当前设备的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;
 }
Ejemplo n.º 16
0
 /** 根据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;
 }
Ejemplo n.º 17
0
 /** 通过包名读取已安装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;
 }
Ejemplo n.º 18
0
  /** 获得设备的横向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;
  }
Ejemplo n.º 19
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;
 }
Ejemplo n.º 20
0
 /**
  * 获取应用的包名
  *
  * @return
  */
 public static String getPackageName() {
   return UIUtils.getContext().getPackageName();
 }
Ejemplo n.º 21
0
 public static void display(View view, String uri) {
   if (utils == null) {
     utils = new BitmapUtils(UIUtils.getContext());
   }
   utils.display(view, uri);
 }