Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Cross-Platform-Entwicklung (https://www.delphipraxis.net/91-cross-platform-entwicklung/)
-   -   Android - Phone oder Tablet (https://www.delphipraxis.net/212511-android-phone-oder-tablet.html)

peer81 20. Feb 2023 16:31

Android - Phone oder Tablet
 
Hallo,

wie kann ich unter Android unterscheiden, ob die App auf einem Handy oder Tablet ausgeführt wird?
Bei
Code:
TJBuild.JavaClass.MODEL
ist das leider nicht zu erkennen.

Unter iOS ist das mit UIDevice recht einfach. Da steht dann beim Modell auch nur iPhone bzw. iPad
Code:
Device := TUIDevice.Wrap(TUIDevice.OCClass.currentDevice);
NSStrToStr(Device.model);
Sowas bräuchte ich für Android auch.

viele Grüße

philipp.hofmann 21. Feb 2023 12:08

AW: Android - Phone oder Tablet
 
Delphi-Quellcode:
class function TMyDeviceInfo.isPhoneMode(form:TForm):boolean;
var FMyCustomMV : TMyDeviceInfo;
    ThisDevice: TDeviceInfo;
begin
  try
    FMyCustomMV := TMyDeviceInfo.Create(form);
    TPlatformServices.Current.SupportsPlatformService(IFMXDeviceService,FMyCustomMV.FDeviceService);
    ThisDevice := FMyCustomMV.GetDevice;
    case ThisDevice.DeviceClass of
      TDeviceInfo.TDeviceClass.Phone:
        begin
          Result:=true;
        end;
      TDeviceInfo.TDeviceClass.Tablet:
        begin
          Result:=false;
        end;
      TDeviceInfo.TDeviceClass.Desktop:
        begin
          Result:=false;
        end
      else begin
        Result:=true;
      end;
    end;
  except on E: Exception do
    begin
      Result:=false;
    end;
  end;
end;

philipp.hofmann 21. Feb 2023 22:09

AW: Android - Phone oder Tablet
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hier noch die gesamte Klasse, du musst nur das Logging entfernen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:12 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz