Search code examples
javaandroidandroid-layoutandroid-activityandroid-orientation

Set portrait only orientation on devices with a screen size of less than 7 inches


I am creating an android application that I want to:

  • Run portrait only orientation on screen sizes (6.9"-)
  • Run portrait and landscape orientations on screen sizes (7"+)

How would I declare this without using androids deprecated (small, normal, large, xlarge) screen sizes?


Solution

  • Store some Boolean in values folders. There can be multiple values folders like values-h720dp or values-w320dp. Then read those data in oncreated method of activity and then set proper orientation. To learn more read this