I would like to detect the device screen orientation by implementing the SensorEventListener, because its current screen orientation is set to portrait by default. I need to do this, because my layout includes some buttons that should rotate independently from their layout and the only way to do this (as long as I know) is by overriding the onConfigurationChanged and adding the corresponding animation to each screen orientation. I don't think an OrientationEventListener would work since the set orientation is fixed to portrait. So how can I retrieve the screen orientation or angle rotations from the sensor itself?
How to detect the device orientation with SensorEventListener?
1.2k views Asked by Lekstadt At
1
There are 1 answers
Related Questions in IMAGEBUTTON
- How can I change status of a checkbox and a ImageButton with one click (from one or from the other)? .Net Maui
- android make image buttons take on the same background selector/drawable as text buttons
- Android (Kotlin): Change Background of an ImageButton in a function
- Changing Image.Url's in VB.Net when there's a repetitive amount
- Maui ImageButton with FontImageSource - how to adjust image size? .net 8
- android.content.ActivityNotFoundException: Unable to find explicit activity class com.example.collegeroamer.NavigationDisplayActivity
- Using custom backgrounds for buttons created through JavaScript
- How to force Image Button dimensions
- Android Studio ImageButton Tooltip has curious behavior if button is created in java source file
- How to set up OnClickListener to a group of imagebutton in Android
- ImageButton Command behaves different from Button Comman when navigating to a map view in .Net MAUI
- how to resize a button programmatically in a fragment
- Displaying imagebuttons on screen
- Stop button from getting greyed out when clicked
- Resources$NotFoundException - Resource ID #<address>
Related Questions in SCREEN-ORIENTATION
- ResizeObserver callback is not being fired when rotated device two times
- Ipad Orientation landscape mode is not working
- How to lock the vertical orientation of an application?
- Is it possible to lock an orientation in a PWA?
- Moving Floating Windows to Corners of Screen All time
- Implementing Auto-Rotation camera in React Native Expo Project
- Getting "no such table: room_table_modification_log" on app rotation
- Android Widgets callbacks on orientation change
- How to present UIViewController to landscape and dismiss to portrait without ever rotating previous ViewControllers?
- Qt/Andriod app, can't seem to get AndroidManifest incorparated
- How to Handle ConfigChanges in Library or Module Java Android?
- tools:replace in android manifest doesn't seem to work
- How to Enable Scrolling in a Flutter ListView.separated Inside a YoutubePlayerScaffold
- Android TV Emulator as rotated and can not be be restored
- Why doesn't "ScreenOrientation: change event" work on the mobile web (iOS Safari)?
Related Questions in ANDROID-SENSORS
- The BH1750 fails to be configured
- Assigning sensor information to image coordinates
- Device pose android emulator rotation values to App
- proximity sensor permission in android app
- I cannot programatically access files on my rooted Galaxy s10+
- Workaround for TYPE_STEP_COUNTER onSensorChanged not triggered in background
- LibGDX camera rotation does not work on Android
- How do I use coroutines in my Kotlin code to read in phone sensor data one by one?
- There is a way to know if other application is using a sensor [Android]
- How to add fixed delay in sensors readings in kotlin?
- Samsung Galaxy Note 9: sensors: wrote an app that reads all sensors, asks for BODY_SENSORS permissions, displays heartrate, how to display SpO2?
- Custom Rotation observer which works like ActivityInfo.SCREEN_ORIENTATION_SENSOR (android:screenOrientation="sensor") in Activities
- How to measure radiation(Non Ionizing) [Android SDK] for a Radiation measuring application
- can someone help me with accessing RGB values on my smart-phone light sensor via Android studio?
- Android Auto Car Sensors: unavailable when testing on a real car
Related Questions in SENSORMANAGER
- There is a way to know if other application is using a sensor [Android]
- How to measure radiation(Non Ionizing) [Android SDK] for a Radiation measuring application
- I can't get the ambient temperature on my phone
- watchOS 10 CMBatchedSensorManager, crashes on startDeviceMotionUpdates / startAccelerometerUpdates
- Memory leak in SensorManager implementation in parent class
- Accelerometer Status is SENSOR_STATUS_UNRELIABLE
- How to apply calibration to accelerometer in android?
- Hide Tooltip dialog when phone is in landscape
- sensor TYPE_STEP_DETECTOR is not working when screen is off
- Unresolved reference: getSensorList in SensorManager.getSensorList
- How to output temperature using Android Studio
- Step Counter in Android Studio doesn't count steps
- Is it possible to send data to light sensor in android?
- Background Service implementing SeneorEventListener only fires once; used to work well a few years ago
- TYPE_STEP_COUNTER sensor not found on a real device(Android Studio)
Related Questions in ROTATEANIMATION
- android scale and rotate animations are not smooth
- Rotate a image 45 degree and come back to the same position on hover
- Rotate animation sequence in Android
- Rotate custom view in android
- Using MEL Expressions on Maya Particles to Control Joint Rotation
- How to rotate SVG back and forth on click?
- Rotate TextView without rotating any text
- Android Compass doesn't point North and keeps changing
- Transform only clockwise on class toggle
- How to rotate only the canvas behind the text
- Rotation of an .obj model using glRotatef
- Android Object Animator executes longer than the duration
- Is it possible to create a simple animation just with translation and rotation in libGDX?
- How to rotate an image in Android and stop it randomly on button pressed
- Is there a way to animate setRotation or should it be replaced with a RotateAnimation?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
An OrientationEventListener will work, even with fixed orientation; see https://stackoverflow.com/a/8260007/1382108. It monitors the sensor according to the documentation. Say you define the following constants:
The numbers correspond to what the OrientationEventListener returns, so if you have a natural landscape device (tablet) you have to take that into account, see How to check device natural (default) orientation on Android (i.e. get landscape for e.g., Motorola Charm or Flipout).
The rotateButtons functions being something like: