Get Android .apk file VersionName or VersionCode WITHOUT installing apk

前端 未结 9 2558
鱼传尺愫
鱼传尺愫 2020-11-28 17:32

How can I get programmatically get the version code or version name of my apk from the AndroidManifest.xml file after downloading it and without installing it.



        
9条回答
  •  自闭症患者
    2020-11-28 18:05

    For the upgrade scenario specifically an alternative approach might be to have a web service that delivers the current version number and check that instead of downloading the entire apk just to check its version. It would save some bandwidth, be a little more performant (much faster to download than an apk if the whole apk isn't needed most of the time) and much simpler to implement.

    In the simplest form you could have a simple text file on your server... http://some-place.com/current-app-version.txt

    Inside of that text file have something like

    3.1.4
    

    and then download that file and check against the currently installed version.

    Building a more advanced solution to that would be to implement a proper web service and have an api call at launch which could return some json, i.e. http://api.some-place.com/versionCheck:

    {
        "current_version": "3.1.4"
    }
    

提交回复
热议问题