首页 > 移动平台 > 详细

Android实例-获取程序版本号

时间:2016-04-20 20:03:33      阅读:266      评论:0      收藏:0      [点我收藏+]

技术分享

 

相关资料: 383675978群号

 

实例源码:

 1 unit Unit1;
 2 
 3 interface
 4 
 5 uses
 6   System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
 7   FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
 8   FMX.Controls.Presentation, FMX.StdCtrls,
 9   xGetVerNo;//Get_OSVer使用
10 
11 type
12   TForm1 = class(TForm)
13     Label1: TLabel;
14     Label2: TLabel;
15     procedure FormCreate(Sender: TObject);
16   private
17     { Private declarations }
18   public
19     { Public declarations }
20   end;
21 
22 var
23   Form1: TForm1;
24 
25 implementation
26 
27 {$R *.fmx}
28 {$R *.NmXhdpiPh.fmx ANDROID}
29 
30 procedure TForm1.FormCreate(Sender: TObject);
31 begin
32   Label2.Text := Get_OSVer;//获取版本号
33 end;
34 
35 end.

第三方源码:

  1 {*******************************************************}
  2 {                                                       }
  3 {       XE7 安卓框架                                    }
  4 {                                                       }
  5 {       版权所有 (C) 2015 打工的程序员                  }
  6 {       日期:    2015.01.15         }
  7 {       源码QQ:2403182533
  8 {                                                       }
  9 {*******************************************************}
 10 
 11 unit xGetVerNo;
 12 
 13 interface
 14 
 15 uses
 16   {$IFDEF MSWINDOWS}
 17   Winapi.Windows,
 18   {$ENDIF}
 19 
 20   {$IFDEF ANDROID}
 21   Androidapi.JNI.GraphicsContentViewText,
 22   Androidapi.JNI.JavaTypes,
 23   FMX.Helpers.Android,
 24   Androidapi.Helpers,
 25   {$ENDIF}
 26 
 27   {$IFDEF IOS}
 28   FMX.Platform.iOS,
 29   iOSapi.Foundation,
 30   Macapi.ObjectiveC,
 31   {$ENDIF}
 32 
 33   {$IFDEF MACOS}
 34   FMX.Platform.Mac,
 35   Macapi.Foundation,
 36   Macapi.ObjectiveC,
 37   {$ENDIF}System.SysUtils ;
 38 
 39  function Get_OSVer:string;
 40 
 41 implementation
 42 
 43 
 44 {$IFDEF MSWINDOWS}
 45 procedure GetBuildInfo(var V1, V2, V3, V4: word);
 46 var
 47   VerInfoSize, VerValueSize, Dummy: DWORD;
 48   VerInfo: Pointer;
 49   VerValue: PVSFixedFileInfo;
 50 begin
 51   VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy);
 52   if VerInfoSize > 0 then
 53   begin
 54       GetMem(VerInfo, VerInfoSize);
 55       try
 56         if GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo) then
 57         begin
 58           VerQueryValue(VerInfo, \, Pointer(VerValue), VerValueSize);
 59           with VerValue^ do
 60           begin
 61             V1 := dwFileVersionMS shr 16;
 62             V2 := dwFileVersionMS and $FFFF;
 63             V3 := dwFileVersionLS shr 16;
 64             V4 := dwFileVersionLS and $FFFF;
 65           end;
 66         end;
 67       finally
 68         FreeMem(VerInfo, VerInfoSize);
 69       end;
 70   end;
 71 end;
 72 
 73 function GetBuildInfoAsString: string;
 74 var
 75   V1, V2, V3, V4: word;
 76 begin
 77   GetBuildInfo(V1, V2, V3, V4);
 78   Result := IntToStr(V1) + . + IntToStr(V2) + . +
 79     IntToStr(V3) + . + IntToStr(V4);
 80 end;
 81 {$ENDIF}
 82 
 83 function Get_OSVer:string;
 84 {$IFDEF MSWINDOWS}
 85 begin
 86   Result:=GetBuildInfoAsString;
 87 end;
 88 {$ENDIF}
 89 
 90 {$IFDEF ANDROID}
 91 var PackageInfo: JPackageInfo;
 92     PackageName: JString;
 93 begin
 94   PackageName := SharedActivityContext.getPackageName;
 95   PackageInfo := SharedActivityContext.getPackageManager.getPackageInfo(PackageName, 0);
 96   Result:= JStringToString(PackageInfo.versionName);
 97 end;
 98 {$ENDIF}
 99 
100 {$IF Defined(IOS) or Defined(MACOS)}
101 var AppNameKey: Pointer;
102     AppBundle: NSBundle;
103     NSAppName: NSString;
104 begin
105   AppBundle := TNSBundle.Wrap(TNSBundle.OCClass.mainBundle);
106   AppNameKey := (NSSTR(CFBundleVersion) as ILocalObject).GetObjectID;
107   NSAppName := TNSString.Wrap(AppBundle.infoDictionary.objectForKey(AppNameKey));
108   Result:=  UTF8ToString(NSAppName.UTF8String)+#13#10;
109 end;
110 {$ENDIF}
111 
112 end.

 

Android实例-获取程序版本号

原文:http://www.cnblogs.com/FKdelphi/p/5413809.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!