Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid SensorManager.getOrientation before event triggered
    text
    copied!<p>I am working on an app for a tablet where the tablet will be in a stand which rotates about a given point. That means <em>very little</em> movement from the tablet when the app is first opened. The app will display various things depending on the rotation of the tablet in the stand. What I cannot seem to find how to do no matter how hard I search is to get the initial orientation in degrees or radians which is comparable to the value of <code>OrientationEventListener.onOrientationChanged(int orientation)</code>. I have an OrientationEventListener configured and my idea was that during the default Activities <code>onCreate</code> method, I would manually call the OrientationEventListener with an updated value.</p> <p>Demo code that doesn't run by itself, but illustrates the point:</p> <pre><code>//No problems at this point in the code, the OrientationManager class //which extends OrientationEventListener properly receives onOrientationChanged //notices OrientationEventListener orientationEventListener; orientationEventListener = new OrientationManager( this, SensorManager.SENSOR_DELAY_NORMAL ); orientationEventListener.enable(); //Here's where the problem is... need to get the current orientation //and "initialize" the OrientationEventListener float[] coords = new float[3]; float[] rotation = new float[16]; SensorManager.getOrientation(rotation, coords); //Test for correct coords values (logs "0.0, -0.0, -0.0") Log.d("DEBUG", Float.toString(coords[0]) + ", " + Float.toString(coords[1]) + ", " + Float.toString(coords[2]) ); //Goal is to be able to call orientationEventListener.onOrientationChanged(??) //with the value that would be sent if the event was called naturally </code></pre> <p>Now, did I submit a question already asked and answered? I've looked at so many SO posts and haven't gotten anywhere.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload