I want to restrict my tablet to launch at specific screen orientation like landscape. I'm taking here about the whole tablet not a specific app, and for sure I'm not taking about locking off the Auto Rotate in the tablet after it launches, I'm taking about restricting the tablet to launch initially at landscape|protrait.

  • 1
    Do you just mean that you want auto rotate turned off when it boots? What are you trying to achieve?
    – Dan Hulme
    Sep 24 '14 at 12:44
  • @DanHulme no, I want to let it open but just want to make the default orientation for the tablet is an orientation i define, So the lockscreen, homepage, ...etc will be at that orientation Sep 24 '14 at 12:48
  • I don't understand. What's the difference between having a "default orientation" and turning off auto rotate?
    – Dan Hulme
    Sep 24 '14 at 12:57
  • @DanHulme when turning on the tablet, It will turn on in specific orientation, in my tablet it's portrait, I want to make it as landscape. Sep 24 '14 at 13:02
  • Surely you could just hold it sideways and it will rotate?
    – RossC
    Sep 24 '14 at 13:53

found the answer, an app that will run just one time.

create an app and add a permission to it's manifest to write_settings & listen-to-boot :

<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

then make a receiver class which extends BroadcastReceivertype, with the fowlloing permissions:

    <receiver android:enabled="true" android:exported="true" 
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <category android:name="android.intent.category.DEFAULT" />

then in the onReceive() method of the receiver class:

ContentResolver contentResolver = context.getContentResolver();
        //To handle device rotation 
        Settings.System.putInt(contentResolver, Settings.System.ACCELEROMETER_ROTATION, 0);
        Settings.System.putInt(contentResolver, Settings.System.USER_ROTATION, Surface.ROTATION_90); // 0 for default, then 90, 180, 270

Then run this app just one time to write that permissions to the system, and then you don't need it again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.