title: Is it possible to execute ADB shell commands from app?
body: <p>I have an <a href="http://www.timingpower.com/rk3288" rel="nofollow noreferrer">Android PC</a> with <strong>root</strong> (out-of-box) connected to an external monitor (HDMI &amp; USB) that always displays in landscape, even though my app specifies portrait in the activity declaration in Manifest:</p>
  
  <pre><code>android:screenOrientation="portrait"
  </code></pre>
  
  <p>I am trying to execute the following command from this <a href="https://stackoverflow.com/questions/13381828/is-it-possible-to-execute-adb-commands-through-my-android-app">SO post</a> to force portrait:  </p>
  
  <pre><code>proc = Runtime.getRuntime().exec("adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0");          
  int exitVal = proc.waitFor();
  </code></pre>
  
  <p>This should set the screen to portrait, but the display always remains in landscape.  No exceptions are recorded.</p>
  
  <p>I have also used the following without success:</p>
  
  <pre><code>process = Runtime.getRuntime().exec("content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0");
  
  process = Runtime.getRuntime().exec(new String[]{"su","-c","content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0"});
  </code></pre>
  
  <p>In both cases, the exit value is [0].  Which means the command terminated normally.</p>
  
  <p>There is only one USB port, and one micro USB port (Power only/no data) on the Android PC.  With debugging enabled, I cannot enumerate the device in DDMS, nor execute shell commands from BASH connecting my dev PC to the micro USB port on the Android PC.  So, I am trying to do this from my Android app.</p>
  
  <p>Please advise</p>