How get the Android App Version with Delphi
November 8, 2017 - Ivan Revelli
November 8, 2017 - Ivan Revelli
[SHOWTOGROUPS=4,20]
Using the JPackageInfo class is simple to retrive the version of your Android application.
This class is already wrapped by Embarcadero in the following unit: Androidapi.JNI.GraphicsContentViewText
my Note: in RAD Studio 10.3.x, "SharedActivityContext.getPackageManager" is deprecated, then, use "TAndroidHelper.Context"!
[/SHOWTOGROUPS]
Using the JPackageInfo class is simple to retrive the version of your Android application.
This class is already wrapped by Embarcadero in the following unit: Androidapi.JNI.GraphicsContentViewText
Код:
...
implementation
{$R *.fmx}
{$IFDEF ANDROID}
uses
Androidapi.Helpers,
Androidapi.JNI.JavaTypes,
Androidapi.JNI.GraphicsContentViewText;
{$ENDIF}
...
{$IFDEF ANDROID}
function fncAndroidAppVersion: string;
var
PackageManager: JPackageManager;
PackageInfo : JPackageInfo;
begin
result := '';
//
PackageManager := TAndroidHelper.Context.getPackageManager; // SharedActivityContext.getPackageManager; {deprecated RAD Studio 10.3.3 Rio}
//
PackageInfo := PackageManager.getPackageInfo(TAndroidHelper.Context.getPackageName { SharedActivityContext.getPackageName deprecated } , 0);
//
result := JStringToString(PackageInfo.versionName);
end;
{$ENDIF}
...
my Note: in RAD Studio 10.3.x, "SharedActivityContext.getPackageManager" is deprecated, then, use "TAndroidHelper.Context"!
[/SHOWTOGROUPS]