From b5f1e5a5c1849d63480f9d1fa27f06874075ccdc Mon Sep 17 00:00:00 2001 From: ctj Date: Wed, 6 Dec 2023 16:15:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E9=83=A8=E5=88=86=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/screen/ScreenActivity.java | 39 ------------------- .../face_chtj/base_iotutils/AppsUtils.java | 20 +++++----- "other/git\344\275\277\347\224\250.txt" | 3 -- 3 files changed, 11 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/com/wave_chtj/example/screen/ScreenActivity.java b/app/src/main/java/com/wave_chtj/example/screen/ScreenActivity.java index cee14ca..1014faf 100644 --- a/app/src/main/java/com/wave_chtj/example/screen/ScreenActivity.java +++ b/app/src/main/java/com/wave_chtj/example/screen/ScreenActivity.java @@ -38,45 +38,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_screen); //这里只是查看屏幕相关信息 与屏幕适配无关 initView(); - screenInfo(); - } - - public void screenInfo() { - WindowManager windowManager = getWindowManager(); - - Display display = windowManager.getDefaultDisplay(); - - DisplayMetrics displayMetrics = new DisplayMetrics(); - - display.getMetrics(displayMetrics); - - int mWidthPixels = displayMetrics.widthPixels; - int mHeightPixels = displayMetrics.heightPixels; - if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17) { - try { - mWidthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(display); - - mHeightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(display); - - } catch (Exception ignored) { - } - } - - if (Build.VERSION.SDK_INT >= 17) { - try { - Point realSize = new Point(); - Display.class.getMethod("getRealSize", Point.class).invoke(display, realSize); - mWidthPixels = realSize.x; - mHeightPixels = realSize.y; - } catch (Exception ignored) { - } - DisplayMetrics dm = new DisplayMetrics(); - getWindowManager().getDefaultDisplay().getMetrics(dm); - double x = Math.pow(mWidthPixels / dm.xdpi, 2); - double y = Math.pow(mHeightPixels / dm.ydpi, 2); - double screenInches = Math.sqrt(x + y); - KLog.d("Screen inches : " + screenInches); - } } public void initView() { diff --git a/base_iotutils/src/main/java/com/face_chtj/base_iotutils/AppsUtils.java b/base_iotutils/src/main/java/com/face_chtj/base_iotutils/AppsUtils.java index 172fb7d..093120e 100644 --- a/base_iotutils/src/main/java/com/face_chtj/base_iotutils/AppsUtils.java +++ b/base_iotutils/src/main/java/com/face_chtj/base_iotutils/AppsUtils.java @@ -57,9 +57,15 @@ public static String getAndroidVersion() { } public static String getAppPath(String pkgName) { - ShellUtils.CommandResult commandResult = ShellUtils.execCommand("pm path " + pkgName, true); - KLog.d("getAppPath() path >> " + commandResult.successMsg); - return commandResult.result == 0 ? commandResult.successMsg.replace("package:", "") : "null"; + try { + PackageManager pm = BaseIotUtils.getContext().getPackageManager(); + ApplicationInfo appInfo = pm.getApplicationInfo(pkgName, 0); + // appInfo.sourceDir 就是APK文件的路径 + return appInfo.sourceDir; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + return null; + } } /** @@ -74,7 +80,7 @@ public static List getDeskTopAppList() { List apps = pm.queryIntentActivities(intent, 0); for (int i = 0; i < apps.size(); i++) { ResolveInfo info = apps.get(i); - KLog.d("getDeskTopAppList() info >> " + info.activityInfo.toString()); + //KLog.d("getDeskTopAppList() info >> " + info.activityInfo.toString()); String pkg = info.activityInfo.packageName; Drawable icon = info.loadIcon(BaseIotUtils.getContext().getPackageManager()); ApplicationInfo ai = pm.getApplicationInfo(info.activityInfo.packageName, PackageManager.GET_ACTIVITIES); @@ -430,11 +436,7 @@ public static boolean isRoot() { public static String getTopApp() { ActivityManager am = (ActivityManager) BaseIotUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE); List list = am.getRunningTasks(1); - if (list != null) { - return (list.get(0).topActivity.getPackageName()); - } else { - return null; - } + return list != null?list.get(0).topActivity.getPackageName():null; } /** diff --git "a/other/git\344\275\277\347\224\250.txt" "b/other/git\344\275\277\347\224\250.txt" index 21d2b65..87b875a 100644 --- "a/other/git\344\275\277\347\224\250.txt" +++ "b/other/git\344\275\277\347\224\250.txt" @@ -13,6 +13,3 @@ git clone git仓库地址 --depth=1 只下载到最新版本,而不是带有 //将某次commit打包到update_201800001.tar中 git diff-tree -r --no-commit-id --name-only f4710c4a32975904b00609f3145c709f31392140 | xargs tar -rf update_201800001.tar - - -