Android Question get version of apk-file without installation

peacemaker

Expert
Licensed User
Longtime User
B4X:
final PackageManager pm = getPackageManager();
String apkName = "example.apk";
String fullPath = Environment.getExternalStorageDirectory() + "/" + apkName;       
PackageInfo info = pm.getPackageArchiveInfo(fullPath, 0);
Toast.makeText(this, "VersionCode : " + info.versionCode + ", VersionName : " + info.versionName , Toast.LENGTH_LONG).show();

Hi, please, help to realise pm.getPackageArchiveInfo
 

Ohanian

Active Member
Licensed User
Longtime User
Hi,

try this :
B4X:
    Dim r, r2 As Reflector
    Dim fullpath As String
    fullpath = File.DirRootExternal & "/sample.apk"
   
    r.Target = r.GetContext
    r.Target = r.RunMethod("getPackageManager")
    r2.Target = r.RunMethod3("getPackageArchiveInfo", fullpath , "java.lang.String", 1, "java.lang.int")
    Log(r2.GetField("versionName"))
    Log(r2.GetField("versionCode"))
 
Upvote 0
Top