ejo4041
ejo4041

Reputation: 325

.apk filename changes after doing adb install

If I do:

adb install myAppRelease-2012-07-24_14-35-14.apk

When I try to reference the actual .apk file after it is installed

PackageManager pm = this.getPackageManager();
for (ApplicationInfo app : pm.getInstalledApplications(PackageManager.GET_META_DATA)) {
    Log.d("PackageList", "package: " + app.packageName + ", sourceDir: " + app.sourceDir);
    String appName = "myAppRelease"
    if(app.packageName.contains("myApp")){
        if(app.sourceDir.contains(appName)){
            apkVersion = app.sourceDir.substring(app.sourceDir.indexOf(appName), app.sourceDir.indexOf(apk));
        }
    }
}

What I see is this:

07-24 14:46:40.190: D/PackageList(7421): package: myApp, sourceDir: /data/app/myApp-1.apk

What I expected to see is this:

07-24 14:46:40.190: D/PackageList(7421): package: myApp, sourceDir: /data/app/myAppRelease-2012-07-24_14-35-14.apk

It appears that it uses

android:label="myApp"
android:versionCode="1"

from the manifest file.

My question is, why doesn't it keep the original .apk filename? I am relying on the .apk filename to display version information for my app.

Upvotes: 0

Views: 1906

Answers (1)

Nikolay Elenkov
Nikolay Elenkov

Reputation: 52936

You can't rely on this, and it definitely doesn't use the version code for the number after the '-'. Especially with newer versions, apps can be moved to the SD card, or forward locked (aka, 'app encryption'), so the actual file on disk can be very different from the original file.

Use PackageManager to get version info, that is guaranteed to be correct and up to date. Change your build system to update the version code and maybe display it in an About dialog or similar so it is easy for users to report it.

Upvotes: 1

Related Questions