title: Adb shell commands to change settings or perform tasks on a phone
body: <p>How do I use adb to perform some automated tasks on my android phone?  I need to find commands that I can issue from the command line (ideally, using a .bat file) that will be capable of more than simply opening an application or sending an input keyevent (button press).  </p>
  
  <p>For instance, I want to toggle Airplane Mode on or off from the command line.  Currently, the best I can do is launch the Wireless &amp; network settings menu and then use input keyevents to click Airplane mode:</p>
  
  <pre><code>adb shell am start -a android.settings.AIRPLANE_MODE_SETTINGS
  adb shell input keyevent 19 &amp; adb shell input keyevent 23
  </code></pre>
  
  <p>There are quite a few drawbacks to this method, primarily that the screen has to be on and unlocked.  Also, the tasks I want to do are much broader than this simple example.  Other things I'd like to do if possible:</p>
  
  <p>1.Play an mp3 and set it on repeat.  Current solution:</p>
  
  <pre><code>adb shell am start -n com.android.music/.MusicBrowserActivity
  adb shell input keyevent 84
  adb shell input keyevent 56 &amp; adb shell input keyevent 66 &amp; adb shell input keyevent 67 &amp; adb shell input keyevent 19
  adb shell input keyevent 23 &amp; adb shell input keyevent 21
  adb shell input keyevent 19 &amp; adb shell input keyevent 19 &amp; adb shell input keyevent 19 &amp; adb shell input keyevent 22 &amp; adb shell input keyevent 22 &amp; adb shell input keyevent 23 &amp; adb shell input keyevent 23
  </code></pre>
  
  <p>2.Play a video.  (current solution: open MediaGallery, send keyevents, similar to above)</p>
  
  <p>3.Change the volume (current solution: send volume-up button keyevents)</p>
  
  <p>4.Change the display timeout (current solution: open sound &amp; display settings, send keyevents)</p>
  
  <p>As before, these all require the screen to be on and unlocked.  The other major drawback to using keyevents is if the UI of the application is changed, the keyevents will no longer perform the correct function.  If there is no easier way to do these sort of things, is there at least a way to turn the screen on (using adb) when it is off?  Or to have keyevents still work when the screen is off?</p>
  
  <p>I'm not very familiar with java.  That said, I've seen code like the following (source: <a href="http://yenliangl.blogspot.com/2009/12/toggle-airplane-mode.html" rel="noreferrer">http://yenliangl.blogspot.com/2009/12/toggle-airplane-mode.html</a>) to change a setting on the phone:</p>
  
  <pre><code>Settings.System.putInt(Settings.System.AIRPLANE_MODE_ON, 1 /* 1 or 0 */);
  </code></pre>
  
  <p>How do I translate something like the above into an adb shell command?  Is this possible, or the wrong way to think about it?</p>
  
  <p>I can provide more details if needed.  Thanks!</p>