PackageManager in Android
What is PackageManager?Ever wondered how apps like “App Manager” or “Clean Master” know everything about your installed apps? The secret is…

PackageManager in Android
What is PackageManager?Ever wondered how apps like “App Manager” or “Clean Master” know everything about your installed apps? The secret is PackageManager — Android’s all-knowing librarian.
PackageManager is a system service in Android that gives you access to information about all installed applications (packages) on the device. Think of it as a librarian who knows everything about every book (app) in the library (device).
1. Basics
val pm: PackageManager = packageManager
This retrieves the PackageManager instance from your Context. It’s a system service — you don’t create it, Android provides it.
2. How PackageManager Works Internally
┌─────────────────────────────────────────────────────────────┐
│ Your App │
│ │ │
│ packageManager │
│ │ │
│ ▼ │
│ PackageManager (Abstract Class) │
│ │ │
│ ▼ │
│ ApplicationPackageManager (Implementation) │
│ │ │
│ ▼ (IPC via Binder) │
│ PackageManagerService (System Process) │
│ │ │
│ ▼ │
│ /data/system/packages.xml │
│ (Database of all installed packages) │
└─────────────────────────────────────────────────────────────┘
Key insight: Your app talks to PackageManagerService running in the system process via Binder IPC (Inter-Process Communication). This is why it’s secure — apps can’t directly modify package data
3. Core Methods You Must Know
3.1 Get All Installed Apps
// Basic - gets all apps
val apps = pm.getInstalledApplications(PackageManager.GET_META_DATA)
// Get packages with more info
val packages = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS)
The flags control what information is returned — without flags, you get minimal data (faster). With flags like GET_META_DATA, the system parses and includes additional manifest data (slower but more complete)
🚀 Top Remote Tech Jobs — $50–$120/hr
🔥 Multiple Roles Open Hiring Experienced Talent (3+ years) Only.
- Frontend / Backend / Full Stack
- Mobile (iOS/Android)
- AI / ML
- DevOps & Cloud
⏳ Opportunities Fill FAST — Early Applicants Get Priority! 👉 **Apply Here**
3.2 Common Flags
Flags are bitmasks that tell PackageManager what extra data to fetch. Combining them with or (|) fetches multiple categories. Using no flags is most performant when you only need basic info.
// No flags - minimal info
PackageManager.GET_META_DATA // Include meta-data from manifest
PackageManager.GET_PERMISSIONS // Include permissions info
PackageManager.GET_ACTIVITIES // Include activity info
PackageManager.GET_SERVICES // Include services info
PackageManager.GET_RECEIVERS // Include broadcast receivers
PackageManager.GET_PROVIDERS // Include content providers
PackageManager.MATCH_SYSTEM_ONLY // Only system apps
PackageManager.MATCH_UNINSTALLED_PACKAGES // Include uninstalled but kept data
3.3 Get Specific App Info
getApplicationInfo() throws NameNotFoundException if the package isn’t installed. Always wrap in try-catch. The loadLabel() and loadIcon() methods access the app’s resources to fetch localized names and icons.
// Get info for a specific package
try {
val appInfo = pm.getApplicationInfo("com.whatsapp", PackageManager.GET_META_DATA)
val appName = appInfo.loadLabel(pm).toString()
val appIcon = appInfo.loadIcon(pm)
} catch (e: PackageManager.NameNotFoundException) {
// App not installed
}
// Get package info (more detailed)
val packageInfo = pm.getPackageInfo("com.whatsapp", PackageManager.GET_PERMISSIONS)
val versionName = packageInfo.versionName
val versionCode = packageInfo.longVersionCode
val permissions = packageInfo.requestedPermissions
4. ApplicationInfo vs PackageInfo
Think of ApplicationInfo as “about the APK file itself” and PackageInfo as “the complete package manifest”. PackageInfo contains ApplicationInfo plus version info, signatures, install times, and declared components.
// ApplicationInfo - About the app itself
val appInfo: ApplicationInfo = pm.getApplicationInfo(packageName, 0)
appInfo.sourceDir // APK path: /data/app/...
appInfo.dataDir // Data path: /data/data/...
appInfo.targetSdkVersion // Target SDK
appInfo.minSdkVersion // Minimum SDK
appInfo.flags // FLAGS_SYSTEM, FLAG_DEBUGGABLE, etc.
// PackageInfo - About the package (includes ApplicationInfo + more)
val pkgInfo: PackageInfo = pm.getPackageInfo(packageName, 0)
pkgInfo.applicationInfo // The ApplicationInfo
pkgInfo.versionName // "1.2.3"
pkgInfo.versionCode // 123
pkgInfo.firstInstallTime // When installed (milliseconds)
pkgInfo.lastUpdateTime // When last updated
pkgInfo.signatures // App signatures (for verification)
5. Identifying System vs User Apps
The flags field in ApplicationInfo is a bitmask. Using bitwise AND (and) checks if specific bits are set. FLAG_SYSTEM indicates apps installed in /system/app or /system/priv-app.
fun isSystemApp(appInfo: ApplicationInfo): Boolean {
return (appInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0
}
fun isUpdatedSystemApp(appInfo: ApplicationInfo): Boolean {
return (appInfo.flags and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0
}
// Usage
ia.forEach { appInfo ->
when {
isSystemApp(appInfo) -> Log.d("TAG", "System app: ${appInfo.packageName}")
else -> Log.d("TAG", "User app: ${appInfo.packageName}")
}
}
6. Uninstalling Apps
// Request uninstall (shows system dialog)
val intent = Intent(Intent.ACTION_DELETE)
intent.data = Uri.parse("package:com.example.someapp")
startActivity(intent)
// For API 28+ with result callback
val intent = Intent(Intent.ACTION_UNINSTALL_PACKAGE)
intent.data = Uri.parse("package:com.example.someapp")
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
startActivityForResult(intent, REQUEST_UNINSTALL)
Note: You cannot silently uninstall apps without root or device owner privileges.
What you cannot do!
| Action | Possible? | Requirement |
|--------------------------|-----------|--------------------------------|
| List installed apps | ✅ | QUERY_ALL_PACKAGES (API 30+) |
| Get app icons/names | ✅ | None |
| Uninstall user apps | ✅ | User confirmation required |
| Uninstall system apps | ❌ | Root access |
| Silent uninstall | ❌ | Device Owner or Root |
| Install apps silently | ❌ | Device Owner or Root |
| Disable system apps | ✅ | Device Admin |
Summary
PackageManager is your gateway to:
- Query all installed apps
- Get details — name, icon, version, permissions, signatures
- Resolve intents — find which apps can handle actions
- Check features — camera, NFC, etc.
- Request uninstall — with user confirmation
Thank you for being a part of the community
Before you go:

👉 Be sure to clap and follow the writer ️👏️️
👉 Follow us: **Linkedin| [Medium](https://medium.com/codetodeploy)**
👉 CodeToDeploy Tech Community is live on Discord — **Join now!**
Note: This Post may contain affiliate links.
메타데이터
- post_id
- e890dfb6e549
- slug
- packagemanager-in-android-e890dfb6e549
- url
- https://medium.com/codetodeploy/packagemanager-in-android-e890dfb6e549
- canonical_url
- https://medium.com/codetodeploy/packagemanager-in-android-e890dfb6e549
- author_url
- https://medium.com/@sehajkahlon437
- status
- ok
- fetched_at
- 2026-06-24 23:31:39