Brian Frost
Brian Frost

Reputation: 13454

How can I get at the file version info of a file when running Delphi on Android?

I'm using Delphi XE7 and I want to log some info about my app to a log file, so I need to port over the GetFileVersionInfo in MSWindows to work in Android. If possible I'd like a general routine that works for any file. I see that there is a Delphi example of how to get file version info in OSX here, but I cant find anything that points me to the relevant Android unit. Can anyone help please?

Upvotes: 1

Views: 1851

Answers (1)

Ondrej Kelle
Ondrej Kelle

Reputation: 37221

Here's a quick example:

uses
  ...
  Androidapi.Helpers,
  Androidapi.JNI.App,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.NativeActivity;

function GetPackageInfo: JPackageInfo;
var
  Activity: JActivity;
begin
  Activity := TJNativeActivity.Wrap(PANativeActivity(System.DelphiActivity)^.clazz);
  Result := Activity.getPackageManager.getPackageInfo(Activity.getPackageName, 0);
end;

procedure TPForm.FormCreate(Sender: TObject);
var
  Info: JPackageInfo;
begin
  Info := GetPackageInfo;
  Label1.Text := Format('versionName: "%s", versionCode: %d', [JStringToString(Info.versionName), Info.versionCode]);
end;

Upvotes: 7

Related Questions