java - android-why I can't get device orientation? -


i want make app shows device orientation on 3 axises while user clicks on button, result 0.0|0.0|0.0 (no rotation) , why?

 package com.example.newp;   import android.app.activity;  import android.hardware.sensormanager;  import android.os.bundle;  import android.view.view;  import android.widget.toast;   public class fullscreenactivity extends activity {  @override public void oncreate(bundle icicle) {     super.oncreate(icicle);     setcontentview(r.layout.activity_fullscreen); }  public void onbuttonclick(view view) {     float[] mgravs = new float[3];     float[] mgeomags = new float[3];     float[] mrotationm = new float[9];     float[] minclinationm = new float[9];     float[] morientation = new float[3];     sensormanager.getrotationmatrix(mrotationm, minclinationm, mgravs,             mgeomags);     sensormanager.getorientation(mrotationm, morientation);     toast.maketext(             this,             string.valueof(morientation[0]) + "|"                     + string.valueof(morientation[1]) + "|"                     + string.valueof(morientation[2]), toast.length_long)             .show(); }  } 

you feeding in wrong values. mgravs [0.0, 0.0, 0.0] , mgeomags. these values should come sensor type_accelerometer , type_magnetic_field respectively. can use values returned sensorevent of these sensors.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -