Page 1 of 1

App based on website

Posted: Wed Jan 04, 2023 5:13 pm
by Billywiz
Hi, I have created an Android app based on a website created in WB but there is a problem. The app opens on a home page with a dropdown menu where a country can be selected. when that country is selected all is ok but if the viewer rotates the screen the page reverts to the home page.
Is there a code I can drop into WB to keep the viewer on the page they were viewing or is it something controlled by Google Play.
Any response welcomed.

Cheers

Re: App based on website

Posted: Fri Jan 06, 2023 7:44 pm
by Billywiz
I found this java script after doing a search and wonder if it would work in WB and if so where would it go.

Code: Select all

@Override     
 public void onConfigurationChanged(Configuration newConfig) {       
        try {     
            super.onConfigurationChanged(newConfig);      
            if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {      
                // land      
            } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {      
               // port       
            }    
        } catch (Exception ex) {       
     }
Cheers

Re: App based on website

Posted: Fri Jan 06, 2023 7:49 pm
by crispy68
When I looked up that code it looks like it is java. I'm not sure how you would use that in WB. Initially i'm inclined to say you can't but I know zero about java.

Re: App based on website

Posted: Fri Jan 06, 2023 8:59 pm
by miguelss
Here is an alternative that may works:

Code: Select all

function preventViewportRotation() {
  const metaViewport = document.querySelector("meta[name=viewport]");
  if (!metaViewport) {
    return;
  }
  metaViewport.setAttribute("content", "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover");
}

window.addEventListener("load", preventViewportRotation);
Cheers,
M.

Re: App based on website

Posted: Sat Jan 07, 2023 9:52 am
by Billywiz
Thanks Miguelss, where would I place this and would it need opening and closing <script>

Cheers

Re: App based on website

Posted: Sat Jan 07, 2023 11:19 am
by miguelss
Hi,

You must copy and paste this code between <head> <head/> tags (into the Site HTLM properties):

Image

This is the whole code:

Code: Select all

  <script>
    function preventViewportRotation() {
      const metaViewport = document.querySelector("meta[name=viewport]");
      if (!metaViewport) {
        return;
      }
      metaViewport.setAttribute("content", "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover");
    }

    window.addEventListener("load", preventViewportRotation);
  </script>
And this is how it must looks after publishing the page:

Code: Select all

<!DOCTYPE html>
<html>
<head>
  <title>My Page</title>
  <script>
    function preventViewportRotation() {
      const metaViewport = document.querySelector("meta[name=viewport]");
      if (!metaViewport) {
        return;
      }
      metaViewport.setAttribute("content", "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover");
    }

    window.addEventListener("load", preventViewportRotation);
  </script>
</head>
<body>
  <!-- Your HTML content goes here -->
</body>
</html>

Cheers,
M.

Re: App based on website

Posted: Sat Jan 07, 2023 2:04 pm
by Billywiz
Thanks to crispy68 and Miguelss for getting back to me.
I have found out that this is a function that can only be altered within the app in the Google Play console so putting code into WB has no affect i'm afraid. So it's back to the drawing board in the play console to figure this one out.

Thanks again guys for your input.

Cheers