Jump to content

How can I get the exact platform type of mobile device from which the app is launched


irigsoft

Recommended Posts

Hello,

I am using a WebView and an Android app (Android 10) to run my app on a mobile device.

in this android app i am using javascriptinterface to call various procedures from my unigui app to android webview.

the problem is this:

1. In the Android app I create a setAndroidOptions function through which I control my mobile app settings from the unigui app.

2. on user login I call setAndroidOptions with specified options.

Everything works fine when used in my Android app (the WebView where the called javascript function exists), but if I call my app from a Google Desktop browser or a mobile browser, the app crashes when running unisession.AddJS('setAndroidOptions(options)' ) because this procedure exists in an android app (but not in google chrome or the mobile browser).

I'm trying to figure out what type UniApplication.UniPlatform is when I launch from the Android app, but when I launch it through a mobile device in a mobile browser, no uniplatform information is returned

  If (UniApplication.UniPlatform  <> [upDesktop])
  AND (UniApplication.UniPlatform  <> [upMobile])
  AND (UniApplication.UniPlatform  <> [upPhone])
  AND (UniApplication.UniPlatform  <> [upTablet])
  AND (UniApplication.UniPlatform  <> [upAndroid])
  AND (UniApplication.UniPlatform  <> [upiPhone])
  AND (UniApplication.UniPlatform  <> [upiPad])
  AND (UniApplication.UniPlatform  <> [upiPod])
  AND (UniApplication.UniPlatform  <> [upiOS])

 

I need to call unisession.AddJS('setAndroidOptions(options)') only when the app has started the session from my android app
If the session is started from a mobile or desktop browser, unisession.AddJS('setAndroidOptions(options)') should not be called. Is there a way to find out which application started the session

I use unigui Professional version.

 

Link to comment
Share on other sites

This is my code in MainModule

...

    function  DetectPlatform():string;
    function  DetectDeviceType():string;
    function  DetectOperationSystem():string;
    function  DetectModel():string;

  public
    { Public declarations }
    uPlat: TUniPlatforms; // uniGUITypes

...

procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject);
uPlat:= UniSession.UniPlatform; 

...

function TUniMainModule.DetectDeviceType: string;
begin
  if (upPhone in uPlat) then
     Result := 'Phone'
  else if (upTablet in uPlat) then
    result := 'Tablet'
  else if (upDesktop in uPlat) then
    result := 'PC';
end;

function TUniMainModule.DetectModel: string;
begin
  if (upiPad in uPlat) then
    Result := 'iPad'
  else if (upiPod in uPlat) then
    Result := 'iPod'
  else if (upiPhone in uPlat) then
    Result := 'iPhone'
  else if (upAndroid in uPlat) then
    Result := 'Android' //  Mobile Device
  else if (upDesktop in uPlat) then
    Result := 'Desktop'; //  PC
end;

function TUniMainModule.DetectOperationSystem: string;
begin
  if (upAndroid in uPlat) then
    Result := 'Android'
  else if (upiOS in uPlat) then
    Result := 'iOS'
  else if (upDesktop in uPlat) then
    Result := 'Desktop OS';
end;

function TUniMainModule.DetectPlatform: string;
begin
  if (upDesktop in uPlat) then
    result := 'Desktop'
  else if (upMobile in uPlat) then
    result := 'Mobile';
end;
 

Link to comment
Share on other sites

6 hours ago, andyhill said:

This is my code in MainModule

...

    function  DetectPlatform():string;
    function  DetectDeviceType():string;
    function  DetectOperationSystem():string;
    function  DetectModel():string;

  public
    { Public declarations }
    uPlat: TUniPlatforms; // uniGUITypes

...

procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject);
uPlat:= UniSession.UniPlatform; 

...

function TUniMainModule.DetectDeviceType: string;
begin
  if (upPhone in uPlat) then
     Result := 'Phone'
  else if (upTablet in uPlat) then
    result := 'Tablet'
  else if (upDesktop in uPlat) then
    result := 'PC';
end;

function TUniMainModule.DetectModel: string;
begin
  if (upiPad in uPlat) then
    Result := 'iPad'
  else if (upiPod in uPlat) then
    Result := 'iPod'
  else if (upiPhone in uPlat) then
    Result := 'iPhone'
  else if (upAndroid in uPlat) then
    Result := 'Android' //  Mobile Device
  else if (upDesktop in uPlat) then
    Result := 'Desktop'; //  PC
end;

function TUniMainModule.DetectOperationSystem: string;
begin
  if (upAndroid in uPlat) then
    Result := 'Android'
  else if (upiOS in uPlat) then
    Result := 'iOS'
  else if (upDesktop in uPlat) then
    Result := 'Desktop OS';
end;

function TUniMainModule.DetectPlatform: string;
begin
  if (upDesktop in uPlat) then
    result := 'Desktop'
  else if (upMobile in uPlat) then
    result := 'Mobile';
end;
 

thank you Andy but my problem is that when I run my app from webview I don't actually get information about uniPlatform it doesn't fall into any of the possible values I don't know why

Link to comment
Share on other sites

29 minutes ago, andyhill said:

The very first thing that is created by a UniGUI connection is the MainModule Session, surely the uPlat variable is seeded on MainModule.Create ?    

You used "uPlat:= UniSession.UniPlatform;" to get uniPlatform but in my case uniPlatform has no value or the value is not in the possible values (I check them one by one)

Link to comment
Share on other sites

UniGUI source code:-

TUniPlatform = (upDesktop, upMobile, upPhone, upTablet, upAndroid, upiPhone, upiPad, upiPod, upiOS);

I develop mostly in standalone server mode and debugging a MainModule Create UniPlatform variable has never failed me ?

I guess I leave this with Sherzod or Farshand or Others - sorry it did not work for you - I would be interested to know why. 

Link to comment
Share on other sites

3 minutes ago, andyhill said:

UniGUI source code:-

TUniPlatform = (upDesktop, upMobile, upPhone, upTablet, upAndroid, upiPhone, upiPad, upiPod, upiOS);

I develop mostly in standalone server mode and debugging a MainModule Create UniPlatform variable has never failed me ?

I guess I leave this with Sherzod or Farshand or Others - sorry it did not work for you - I would be interested to know why. 

thank You for Your try, what is different between uniAndroid and uniMobile. I know the list TUniPlatform = (upDesktop, upMobile, upPhone, upTablet, upAndroid, upiPhone, upiPad, upiPod, upiOS), and try all possible values to get what kind is webView on Android app ( i guest that are uniAndroid or uniMobile  but they dont ).

I use StandAlone app, start session on webview in Android (or mobile browser) and uniPlatform is not in list (upDesktop, upMobile, upPhone, upTablet, upAndroid, upiPhone, upiPad, upiPod, upiOS)

i try to get uniPlatform by this way:

If (UniApplication.UniPlatform  = [upDesktop])
  OR (UniApplication.UniPlatform  = [upMobile])
  OR (UniApplication.UniPlatform  = [upPhone])
  OR (UniApplication.UniPlatform  = [upTablet])
  OR (UniApplication.UniPlatform  = [upAndroid])
  OR (UniApplication.UniPlatform  = [upiPhone])
  OR (UniApplication.UniPlatform  = [upiPad])
  OR (UniApplication.UniPlatform  = [upiPod])
  OR (UniApplication.UniPlatform  = [upiOS])

I expect to get uniAndroid or upMobile but don't.

Link to comment
Share on other sites

42 minutes ago, andyhill said:

Did you initialise the variable

procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject);
begin
  uPlat:= UniSession.UniPlatform; 

Thanks, Your way works.

But that's not enough because I get Android on any mobile device, whether it's a mobile browser or a web view. my solution is: i added a specific variable in the mobile url that uses the webview

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...