Search code examples
androidaccelerometerscreen-rotation

Android Screen rotation, ACCELEROMETER_ROTATION


am trying to make my Android application rotate as soon as it run and fix the rotation, i have tried a wide range of method like : Settings.System.ACCELEROMETER_ROTATION it doesn't make it rotate, but it just enable the rotate feature, i need your help thank you in advance (^_^). here is my code :

`

TableRow tableRow;
Time HourProgram;
RotateAnimation r;
int H = 12000, M = 1200;
int averageConsultationTime = 30;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.table);
    setAutoOrientationEnabled(this, true);

}

public static void setAutoOrientationEnabled(Context context,
        boolean enabled) {
    Log.i("OK", "setAutoOrientationEnabledOK");
    Settings.System.putInt(context.getContentResolver(),
            Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}

public static boolean getRotationScreenFromSettingsIsEnabled(Context context) {

    int result = 0;
    try {
        result = Settings.System.getInt(context.getContentResolver(),
                Settings.System.ACCELEROMETER_ROTATION);
    } catch (Settings.SettingNotFoundException e) {
        e.printStackTrace();
    }

    return result == 1;
}

`


Solution

  • You can just add this attribute to your activity in the AndroidManifest:

    android:screenOrientation="landscape"
    

    You can find more information about Android activities attributes here.