Skip to content

Commit

Permalink
提交部分工具优化
Browse files Browse the repository at this point in the history
  • Loading branch information
ctj committed Dec 6, 2023
1 parent 1f98b68 commit b5f1e5a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 51 deletions.
39 changes: 0 additions & 39 deletions app/src/main/java/com/wave_chtj/example/screen/ScreenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand All @@ -74,7 +80,7 @@ public static List<AppEntity> getDeskTopAppList() {
List<ResolveInfo> 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);
Expand Down Expand Up @@ -430,11 +436,7 @@ public static boolean isRoot() {
public static String getTopApp() {
ActivityManager am = (ActivityManager) BaseIotUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> 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;
}

/**
Expand Down
3 changes: 0 additions & 3 deletions other/git使用.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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



0 comments on commit b5f1e5a

Please sign in to comment.