本文最后更新于:2024年12月24日 晚上
获取进程名字
【Android】获取当前进程名的四种方法及效率对比_android获取当前进程名-CSDN博客: https://blog.csdn.net/qq_23049111/article/details/126097443
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
| fun getAppProcessName(): String { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { return Application.getProcessName() } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { val processName = Reflector.on("android.app.ActivityThread").method("currentProcessName") .call<String>() Log.d(TAG, "getAppProcessName: $processName") return processName } catch (e: Exception) { Log.e(TAG, "getAppProcessName error", e) return "" } } else { try { val processName = Reflector.on("android.app.ActivityThread").method("currentPackageName") .call<String>() Log.d(TAG, "getAppProcessName: $processName") return processName } catch (e: Exception) { Log.e(TAG, "getAppProcessName error", e) return "" } } }
|
获取应用名称
Android 获取应用的icon、名字、版本号_查看安卓app类名-CSDN博客: https://blog.csdn.net/LoveDou0816/article/details/78135201
1 2 3 4 5 6 7 8 9 10 11 12 13
| fun Context.getAppName(pkgName: String): String { return try { val info: PackageInfo = packageManager.getPackageInfo(pkgName, 0) info.applicationInfo.loadLabel(packageManager).toString() } catch (e: PackageManager.NameNotFoundException) { Log.e(TAG, "getAppName error", e) "" } catch (e: Resources.NotFoundException) { Log.e(TAG, "getAppName error", e) "" } }
|