Advertisement
antonydanby

Retrieve ver info from APK in FireMonkey

Apr 18th, 2023
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.60 KB | Source Code | 0 0
  1. { Q: In Delphi FMX how do I retrieve the version information from the APK
  2.  
  3. A: In Delphi FMX, you can retrieve the version information from an APK by using the TJPackageInfo class, which is part of the Android API. Here's an example of how to use TJPackageInfo to retrieve the version information from an APK: }
  4.  
  5. uses
  6.   Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.JavaTypes;
  7.  
  8. function GetVersionInfo: string;
  9. var
  10.   PackageInfo: JPackageInfo;
  11.   PackageManager: JPackageManager;
  12.   VersionName: JString;
  13.   VersionCode: Integer;
  14. begin
  15.   PackageManager := SharedActivity.getPackageManager;
  16.   PackageInfo := PackageManager.getPackageInfo(
  17.     SharedActivityContext.getPackageName, 0);
  18.   VersionName := PackageInfo.versionName;
  19.   VersionCode := PackageInfo.versionCode;
  20.  
  21.   Result := 'Version name: ' + JStringToString(VersionName) + sLineBreak +
  22.             'Version code: ' + IntToStr(VersionCode);
  23. end;
  24.  
  25. { This function first retrieves a PackageManager object from the current activity, and then uses that object to retrieve a PackageInfo object for the current package (identified by its package name). The PackageInfo object contains the version information for the package, including the version name and version code.
  26.  
  27. The function then converts the version name (which is a JString object) to a Delphi string using the JStringToString function, and returns both the version name and version code as a formatted string.
  28.  
  29. Note that you will need to add the Androidapi.JNI.GraphicsContentViewText and Androidapi.JNI.JavaTypes units to your uses clause to use the necessary classes and functions. }
  30.  
Tags: chatGPT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement