Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- { Q: In Delphi FMX how do I retrieve the version information from the APK
- 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: }
- uses
- Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.JavaTypes;
- function GetVersionInfo: string;
- var
- PackageInfo: JPackageInfo;
- PackageManager: JPackageManager;
- VersionName: JString;
- VersionCode: Integer;
- begin
- PackageManager := SharedActivity.getPackageManager;
- PackageInfo := PackageManager.getPackageInfo(
- SharedActivityContext.getPackageName, 0);
- VersionName := PackageInfo.versionName;
- VersionCode := PackageInfo.versionCode;
- Result := 'Version name: ' + JStringToString(VersionName) + sLineBreak +
- 'Version code: ' + IntToStr(VersionCode);
- end;
- { 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.
- 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.
- 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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement