{"id":16,"date":"2012-10-23T04:24:48","date_gmt":"2012-10-23T04:24:48","guid":{"rendered":"https:\/\/code4reference.com\/?p=16"},"modified":"2012-10-23T04:24:48","modified_gmt":"2012-10-23T04:24:48","slug":"code4referencehow-to-find-android-default-screen-orientation","status":"publish","type":"post","link":"https:\/\/code4reference.com\/?p=16","title":{"rendered":"Code4ReferenceHow to find Android default screen orientation"},"content":{"rendered":"<h2><a href=\"http:\/\/code4reference.com\/2012\/06\/android-default-screen-orientation\/\">How to find Android default screen orientation.<\/a><\/h2>\n<p>Recently while developing my personal project, I had a requirement to find the default screen orientation of device. Tablet default screen orientation is landscape whereas Mobile phone default screen orientation is\u00a0portrait.\u00a0<\/p>\n<p>Well after a little bit of research I found that <i>getRotation<\/i> method can fetch me the default orientation. This method can be used in the following way:\u00a0<\/p>\n<pre>this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()\n               .getRotation()<\/pre>\n<p>\u00a0If this method returns\u00a0<b>Surface.ROTATION_0<\/b> (no rotation) then it means that the current screen orienation is the default screen orientation. \u00a0For example, if the tablet is currently in \u00a0landscape orientation then this method returns <b>Surface.ROTATION_0(value 0\u00d700000000)<\/b> else\u00a0it returns either\u00a0\u00a0Surface.ROTATION_90 or Surface.ROTATION_270.<\/p>\n<p>This arises one more question as how to determine the current orientation of the screen. It can be determined by the following method.<\/p>\n<pre>this.getResources().getConfiguration().orientation<\/pre>\n<p>The return value can be either of these<\/p>\n<pre>Configuration.ORIENTATION_LANDSCAPE\nConfiguration.ORIENTATION_PORTRAIT\nConfiguration.ORIENTATION_SQUARE<\/pre>\n<p>These values themselves suggest the orientation of the screen.\u00a0<\/p>\n<p>Your valuable comments are always welcomed. It will help to improve my post and understanding.<\/p>\n<p><i>\u201cBy three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest.\u201d<\/i><br \/>\nBy : Confucius<\/p>\n<p><a href=\"http:\/\/code4reference.com\/tag\/android\/\">Android<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to find Android default screen orientation. Recently while developing my personal project, I had a requirement to find the default screen orientation of device. Tablet default screen orientation is landscape whereas Mobile phone default screen orientation is\u00a0portrait.\u00a0 Well after a little bit of research I found that getRotation method can fetch me the default [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16"}],"version-history":[{"count":0,"href":"https:\/\/code4reference.com\/index.php?rest_route=\/wp\/v2\/posts\/16\/revisions"}],"wp:attachment":[{"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code4reference.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}