I'm using accelometer sensor to detect whether my device is flat on a table or not. The weird thing is even when I put my phone flat or rotate it on it's side the value is always between 90 and 100! This shouldn't be correct! am I missing something? Here is my code:
   float[] values = event.values;
    // Movement
    float x = values[0];
    float y = values[1];
    float z = values[2];
    float norm_Of_g =(float) Math.sqrt(x * x + y * y + z * z);
    // Normalize the accelerometer vector
    x = (x / norm_Of_g);
    y = (y / norm_Of_g);
    z = (z / norm_Of_g);
    int inclination = (int) Math.round(Math.toDegrees(Math.acos(y)));
    Log.i("tag","incline is:"+inclination);
    if (inclination < 25 || inclination > 155)
    {
        // device is flat
        Toast.makeText(this,"device flat - beep!",Toast.LENGTH_SHORT);
    }
Edit: I'm using this code : How to measure the tilt of the phone in XY plane using accelerometer in Android
