I'm working on an app that extends the functionality of another, existing app. I want to know what the easiest way is to determine, through code, whether the first app is installed, preferably by referencing it by com.whoever.whatever but almost any criteria would be helpful.
Asked
Active
Viewed 1.1k times
3 Answers
33
android.content.pm.PackageManager mPm = getPackageManager(); // 1
PackageInfo info = mPm.getPackageInfo(pName, 0); // 2,3
Boolean installed = info != null;
- Used in an activity, you need a context to get the PackageManager
- Throws
PackageManager.NameNotFoundException
, I guess. check! - pName is something like 'com.yourcompany.appname', the same as the value of 'package' in the manifest of the app

Curtis
- 101,612
- 66
- 270
- 352

Reza Mohammadi
- 645
- 5
- 13
-
1This works. But also, if it is a donation app or something to this effect, you can also call an Intent from the donation app and check the return value. In theory this would prevent an apk being created using the same pName and distributed outside of the store. Just a thought... – Anthony Graglia Jan 23 '11 at 17:13
2
The recommended way is to check whether the other application publishes an Intent. Most Intent are not owned by a particular app, so, say, if you're looking for a program that publishes "sending mail" intent, the program that gets opened may be Gmail application or Yahoo Mail application, depending on the user's choice and what was installed in the system.
You may want to look at this: http://developer.android.com/guide/topics/intents/intents-filters.html

Lie Ryan
- 62,238
- 13
- 100
- 144
0
Starting Android 12, this requires android.permission.QUERY_ALL_PACKAGES permission, which Google Play may or may not allow you to have
See more details https://developer.android.com/training/package-visibility

novosibiryak
- 1
- 1