Delphi XE5 Android程序常用的unit

首先要uses

Delphi XE5封裝了一些Android相關的api

uses
澳门新葡亰3522平台游戏,  FMX.Platform.Android,
  Androidapi.JNI.Telephony,
  Androidapi.JNI.Provider ,
  Androidapi.JNIBridge,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.JNI.JavaTypes,
  FMX.Helpers.Android;
接著放上Button,在Click事件打上

Androidapi.Jni

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

Androidapi.JNI.Os

Androidapi.JNI.JavaTypes

Androidapi.JNIBridge