Android screen orientation according to mobile screen width - android

I'm creating an aplication with Phonegap. The point is if I can put a limit for screen orientation namly I want that the device can't change orientation to landscape unless the device screen width is more than 480px.

As far as I know, this is not possible. You have either screen rotation, or off. Not conditionally on. You can change your GUI of your app, depending on screen rotation and size.
Your question is to general to give a specific answer. But if you want to see an example, check out my repo jpHolo. It features an interface for smartphones and tablets and you can add code for screen changes easily.
https://github.com/teusinkorg/jpHolo

Related

Android 9 Screen Rotation Approach

Our team has recently updated a system application (installed in priv-app) from Android 5 to Android 9. This seems to have broken the previously working (and relatively well documented approach) of programmatically flipping the device orientation.
We had been using this approach and it had worked at globablly flipping the device orientation 180 degrees:
Settings.System.putInt( context.getApplicationContext().getContentResolver(), Settings.System.USER_ROTATION, 2)
We check each time to make sure the accelerometer rotation is disabled also. The setting does in fact stick as when interrogate the settings provider and can see the value being updated, the screen is simply not reacting, even after a reboot etc..
I'm trying to understand if Android 9 introduced any further gotchas that can prevent a screen rotation from happening, would be grateful if anyone had any insight on this particular issue?
You can instead use Activity.setRequestedOrientation() if its a particular Activity your want to change. This can be set explicitly to portrait, reverse portrait, landscape, reverse landscape, etc... It will then lock to the orientation you set. You can use the various sensor values if you want it to be flexible for the user.
If you want to know what your current orientation is (including reverse orientations) it can be complicated but I just answered my own question here about how to do it - Android sensor orientation problems with edge-to-edge insets
If you want to change the system rotation
You need to ensure ACCELEROMETER_ROTATION is off and then the value you use needs to come from the surface rotation constants (which are relative to your displays natural orientation) - https://developer.android.com/reference/android/view/Surface#ROTATION_0
Another quick edit - any Activity can override this setting (including a launcher) for themselves. So it may be that whatever you are running is actually what changed to lock or allow certain orientations.

I want my app to look the same on every phone in Android Studio

I designed an app with dp unit. I also used RelativeLayout. I designed app while Pixel 3XL screen selected like this. After i finished the design i changed the screen to the Pixel like this. Now my design looks bigger.Look the red line. Not equal to the Pixel 3XL. I want my app to look the same on every phone. Thank you.
From Document:
Android devices come in all shapes and sizes, so your app's layout
needs to be flexible. That is, instead of defining your layout with
rigid dimensions that assume a certain screen size and aspect ratio,
your layout should gracefully respond to different screen sizes and
orientations. By supporting as many screens as possible, your app can
be made available to the greatest number of users with different
devices, using a single APK. Additionally, making your app flexible
for different screen sizes ensures that your app can handle window
configuration changes on the device, such as when the user enables
multi-window mode.
This page shows you how to support different screen sizes with the
following techniques:
Use view dimensions that allow the layout to resize Create alternative
UI layouts according to the screen configuration Provide bitmaps that
can stretch with the views
https://developer.android.com/training/multiscreen/screensizes
https://material.io/design/layout/responsive-layout-grid.html
Try using constraintLayout if you want to build responsive designs.I have tested it on multiple devices and google also recommends it.Go through the link.
https://developer.android.com/training/constraint-layout

How to remove vertical letterboxing from android TV app?

I have submitted an android tv app to the play store and got rejection email explaining the reason that:
Not designed in landscape orientation. Your app has vertical letterboxing when displayed on TV's. Please design your app to be displayed in landscape orientation.
I have tried removing margins from the screen designs but it didn't helped me. Can anyone help me in solving this issue. I have already added the leanback launcher intent and software.leanback uses feature tag with true value.
Thanks In Advance.
You don't want to just remove padding/margins without explicitly testing it. You have to deal with overscan on TVs, so having anything important at the very edge means it might not be visible on some devices. On ATV, the normal values are 48dp horizontally and 27dp vertically. If you're using the Leanback library, this is handled for you.
Vertical letterboxing is almost always a case of something that's inherently portrait orientation being show in landscape.
You should verify that none of your activities have a screenOrientation set (unless it's landscape). It's pretty common for people to forget one particular screen is forced to portrait (e.g., a login screen from a 3rd party SDK). A quick launch of each Activity/Fragment on an ATV emulator will also help you catch anything wildly wrong.
If your app has video, you also want to make sure you're reasonably matching the aspect ratio. For example, you should display a 16x9 video instead of a 2x3 video on landscape.
I have almost same problem:
To fix this issue, please ensure that your app/game is displayed in landscape orientation and the content fills the entire screen.
Alternatively, if your app requires content to be displayed in its original aspect ratio or is of older quality, please include a disclaimer in your app description or within the app prior to the content playing. You may want to refer to our TV Layouts documentation for additional guidance.
I choosed Alternate solution because the sent me a screenshot of old video in 4:3 scale.
I symply added to app description text about possibility to show content in 4:3 aspect ratio. I hope ot will help. Will it?

How do you get all available device densities via android studio?

I did find a lot of code to get current screen density in dpi and scale ratio and etc.
However what I am looking for a way to get a list of all densities that are shown inside the screen zoom view in device settings of a phone -
How do you get all available device densities via android studio?
please see a screenshot for more details on the question:
Thanks in advance!
You are mixing different things here. Density it's something tight to the device, in order to support dp and sp locally (based on screen resolution). Which means just factor to multiply pixels on this device.
You question "To get a list of all densities that are shown inside the screen zoom view in device settings of a phone" makes no sense. Since you are asking about some magic list of factors.
Now, to answer question, how to make something similar shown in the screen is pretty easy. You implementation starts with default and correct density supported by this device (as shown on image, we have centered slider), and just applying new factor changes of this density, based on user input from slider. So all your views should be aligned from encapsulated logic with using this changed scale factor (based on initial density of the device).

How to set desired landscape orientation

I know you can set orientation using android:screenOrientation statically and setRequestedOrientation programatically. However the problem is that if I use either of these to set the screen orientation I do not get to choose which landscape or which portrait I want. To wit, flipping the phone 180 degrees does not rotate the view but rather just appears upside down to the user. I cannot use screenOrientation="sensor", because in some cases I would only want the view to be landscape OR portrait and seldom both. This seems insignificant until you consider external hardware.
If I developed an app and set the layout to android:screenOrientation="landscape", the app would only display correctly if the left side of the droid were sitting on a desk. Unforunately the left side is where the usb port is, so the phone would not sit very well on that side if it were plugged in. Unless of course they used a docking station but that is not the kind of help I am looking for. If the right side of the phone is sitting on the desk to allow for the cord, the display appears upside down. I tried posting an image but being a new user I was not able to do so.
What I would like to know is how to programmatically choose which landscape (Surface.ROTATION_90,Surface.ROTATION_270) or portrait (Surface.ROTATION_0,Surface.ROTATION_180) orientation I wish the user to see, but more importantly allow them to do so in the app's settings activity. I have googled for quite awhile and all I can find are sensors that tell you when the orientation/rotation has changed and to what, but none show how to programmatically set either.

Categories

Resources