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.
-
1Do you just mean that you want auto rotate turned off when it boots? What are you trying to achieve?– Dan HulmeCommented Sep 24, 2014 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– Muhammed RefaatCommented Sep 24, 2014 at 12:48
-
I don't understand. What's the difference between having a "default orientation" and turning off auto rotate?– Dan HulmeCommented Sep 24, 2014 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.– Muhammed RefaatCommented Sep 24, 2014 at 13:02
-
Surely you could just hold it sideways and it will rotate?– RossCCommented Sep 24, 2014 at 13:53
|
Show 4 more comments
1 Answer
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"
android:name="com.example.BootCompletedReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
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.