admin

[android] delphi 开发 安卓android手机获取imei唯一识别码

unit Unit2;


interface


uses

  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,

  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,

  FMX.Platform.Android,

  Androidapi.JNI.Telephony,

  Androidapi.JNI.Provider ,

  Androidapi.JNIBridge,

  Androidapi.JNI.GraphicsContentViewText,Androidapi.Helpers,

  Androidapi.JNI.JavaTypes,

  Androidapi.JNI.app,

  FMX.Helpers.Android, FMX.Controls.Presentation, FMX.StdCtrls;

type

  TForm2 = class(TForm)

    Button1: TButton;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;


var

  Form2: TForm2;


implementation


{$R *.fmx}

{$R *.LgXhdpiPh.fmx ANDROID}

{$R *.iPad.fmx IOS}


procedure TForm2.Button1Click(Sender: TObject);

var

  obj: JObject;

  tm: JTelephonyManager;

  IMEI: String;

begin

  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.TELEPHONY_SERVICE);

  if obj <> nil then

  begin

    tm := TJTelephonyManager.Wrap((obj as ILocalObject).GetObjectID);

    if tm <> nil then

      IMEI := JStringToString(tm.getDeviceId);

  end;

  if IMEI = '' then

      IMEI := JStringToString(TJSettings_Secure.JavaClass.getString(SharedActivity.getContentResolver,TJSettings_Secure.JavaClass.ANDROID_ID));


  ShowMessage('IMEI :' + #13 + IMEI);

end;


end.


#1楼
发帖时间:2016-10-11   |   查看数:0   |   回复数:0
游客组