How get the Android App Version with Delphi by Ivan Revelli

emailx45

Местный
Регистрация
5 Май 2008
Сообщения
3,571
Реакции
2,439
Credits
574
How get the Android App Version with Delphi
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

Код:
...
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]