title: Changing Screen Orientation in android
body: <p>i want to change the Screen Orientation to <strong>SENSOR</strong> when the Frame Layout is visible (i.e video is playing in full screen) which is working fine , But i want to revert it back to <strong>PORTRAIT</strong> when the frame layout is gone Which is Not working (No Errors, but the code is not doing anything) i have tried this so far </p>
  
  <pre><code>// Finally show the custom view container.
          mCustomViewContainer.setVisibility(View.VISIBLE);
          mCustomViewContainer.bringToFront();
  
          // auto orientation change if video is playing
          if (mCustomViewContainer.getVisibility() == View.VISIBLE) {
              setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
          } else {        
              setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
          }       
      }
  </code></pre>
  
  <p>the workaround i found was to change orientation onbackpressed because that's where i am hiding my frame layout also </p>
  
  <pre><code>@Override
  public void onBackPressed() {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
      exitdlg = (View) findViewById(R.id.exitdlg);
      options1 = (View) findViewById(R.id.options1);
      if (mCustomView != null) {// close full screen video view if open
          mWebChromeClient.onHideCustomView();// FULL-SCREEN VIDEO-5
      } else if (options1.getVisibility() == View.VISIBLE) {
          findViewById(R.id.options1).setVisibility(View.GONE);
  
      } else if (exitdlg.getVisibility() == View.GONE) {// this brings
                                                          // up/hides
          // menu 1 on hardware
          // options btn
          // Its visible
          findViewById(R.id.exitdlg).setVisibility(View.VISIBLE);
      } else {
          // Either gone or invisible
          findViewById(R.id.exitdlg).setVisibility(View.GONE);
  
      }
  }
  </code></pre>
  
  <p>but it only works when i press back button Twice which i don't want. 
  <a href="https://stackoverflow.com/questions/17706580/youtube-video-not-playing-in-webview">that's</a> where i got this code </p>