Delphi XE5讀出Android IMEI ID

首先要uses

uses
  FMX.Platform.Android,
  Androidapi.JNI.Telephony,
  Androidapi.JNI.Provider ,
  Androidapi.JNIBridge,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.JavaTypes,
  FMX.Helpers.Android;

接著放上Button,在Click事件打上

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);