Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8216799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:15:24+00:00 2026-06-07T12:15:24+00:00

So i just tested an app that i have been testing on phone devices,

  • 0

So i just tested an app that i have been testing on phone devices, on a samsung tablet.

The application updates graphics based on accelermoter data and i noticed that on the tablet it is treating landscape as portrait.. its fine on a naturally portrait mode device..

any ideas how i can ajust this so it works on both:

public class ARLaunch extends Activity {

/** Open Camera View **/    
private CamLayer camPreview;
/** Open Camera View **/ 
private GLLayer glView;

private WakeLock mWakeLock;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // requesting to turn the title OFF
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    // making it full screen
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

    //Set Screen Orientation
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    try{
        final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        this.mWakeLock = pm.newWakeLock(
                PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag");


        //Create Intance of Camera
        camPreview = new CamLayer(this.getApplicationContext());

        //Create Instance of OpenGL
        glView = new GLLayer(this);

        //FrameLayOut for holding everything
        FrameLayout frame = new FrameLayout(this);
        // set as main view
        setContentView(frame);

        // add Camera to view 
        frame.addView(camPreview, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

        frame.addView(glView);



    } catch(Exception e){}
}
/** Remember to resume the glSurface  */
@Override
protected void onResume() {
    super.onResume();
    try{
    this.mWakeLock.acquire();
    } catch (Exception ex){}
    glView.onResume();
    glView.setZOrderOnTop(true);
}
/** Also pause the glSurface  */
@Override
protected void onPause() {
    super.onPause();
    try{
        this.mWakeLock.release();
    } catch (Exception ex){}

    glView.onPause();

}

public void displayOri(float acc, float ori){

}

}

public class PhoneOrientation {
private SensorManager sensorMan;
private Sensor sensorAcce;
private Sensor sensorMagn;
private SensorEventListener listener;
private float matrix[]=new float[16];
private Context ctx;

public PhoneOrientation(Context context) {
    ctx = context;
}

public void start(Context context) {
    listener = new SensorEventListener() {
        private float orientation[]=new float[3];
        private float acceleration[]=new float[3];

        public void onAccuracyChanged(Sensor arg0, int arg1){}

        public void onSensorChanged(SensorEvent evt) {
            int type=evt.sensor.getType();

            //Smoothing the sensor data a bit seems like a good idea.
            if (type == Sensor.TYPE_MAGNETIC_FIELD) {
                orientation[0]=(orientation[0]*1+evt.values[0])*0.5f;
                orientation[1]=(orientation[1]*1+evt.values[1])*0.5f;
                orientation[2]=(orientation[2]*1+evt.values[2])*0.5f;
            } else if (type == Sensor.TYPE_ACCELEROMETER) {
                acceleration[0]=(acceleration[0]*2+evt.values[0])*0.33334f;
                acceleration[1]=(acceleration[1]*2+evt.values[1])*0.33334f;
                acceleration[2]=(acceleration[2]*2+evt.values[2])*0.33334f;
            }
            if ((type==Sensor.TYPE_MAGNETIC_FIELD) || (type==Sensor.TYPE_ACCELEROMETER)) {
                float newMat[]=new float[16];
                //Toast toast = Toast.makeText(ctx.getApplicationContext(), "accel", Toast.LENGTH_SHORT);
                //toast.show();
                SensorManager.getRotationMatrix(newMat, null, acceleration, orientation);
                SensorManager.remapCoordinateSystem(newMat,
                        SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X,
                        newMat);
                matrix=newMat;
            }
        }
    };

    sensorMan = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
    sensorAcce = sensorMan.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
    sensorMagn = sensorMan.getSensorList(Sensor.TYPE_MAGNETIC_FIELD).get(0);

    sensorMan.registerListener(listener, sensorAcce, SensorManager.SENSOR_DELAY_GAME);
    sensorMan.registerListener(listener, sensorMagn, SensorManager.SENSOR_DELAY_GAME);      
}

public float[] getMatrix() {
    return matrix;
}

public void finish() {
    sensorMan.unregisterListener(listener);
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:15:27+00:00Added an answer on June 7, 2026 at 12:15 pm

    Read this post: http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html

    Also, don’t use a wake lock just to keep the screen on while your activity is visible. Use the KEEP_SCREEN_ON flag on a view instead and you can drop the wake lock permission.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that has been running fine since its launch over a
I have always been using virtualenv for testing my app in localhost since I
I have an ASP/C#(4.0) app that was been running on my machine for several
We have an app that has crashed on armv6 iOS devices coming from the
I have a Rails app that I have successfully tested with Mongrel and Webkit.
I have a paid app that's been out in the Android Market for a
I have built a Facebook app using the Javascript SDK that has been up
I have been tasked with completing an app that is 75% done. It has
I just publicated yesterday my first android application. I did not tested on android
My MySQL database can store the euro symbol just fine (as I have tested

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.