1

I need to check if a certain application is installed (I know what it is by its package name "com.domain.appname"), and if it's not installed show a toast message. If it's installed, I need to get its version and show a toast message with its version. Is it possible?

The other question (How to get a list of installed android applications and pick one to run) doesn't mention getting the version.

Community
  • 1
  • 1
Minion
  • 2,497
  • 4
  • 27
  • 29
  • The linked question is to get a list of all applications while this question to get information about specific applications with known package names so I don't think the linked question is close enough. That being said, it's a possible dup of this one: http://stackoverflow.com/questions/2610473/trying-to-get-package-version-information-to-display-in-an-about-message – Michael Celey Sep 13 '12 at 17:21
  • 1
    @MCeley I know that it is pretty hard to get an entry out of a list... so if someone asks on how to set the text color to white you wouldn't mark it duplicated with one asking for blue? – WarrenFaith Sep 13 '12 at 17:47
  • @WarrenFaith Alright, you got me on that one. I just thought the question I linked was a bit closer to what the poster was asking. – Michael Celey Sep 13 '12 at 18:15
  • Well I had to choose one out of many :) – WarrenFaith Sep 13 '12 at 21:08

1 Answers1

2

You can get that information from the PackageManager.

private String getVersionName(String packageName) {
    String version = null;
    try {
        PackageInfo info = getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA);
        version = pInfo.versionName;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return version;
}
Michael Celey
  • 12,645
  • 6
  • 57
  • 62
  • Thanks a lot, it works perfect (sorry for duplicate, but the code of the other posts doesn't works) Thanks again :) – Minion Sep 13 '12 at 18:25