title: Is there a way to do a screenshot on android service code?
body: <p>I want to do a screenshot of my phone outside the application.
  I created an android service that I can run my app in the background but I didn't found any solutions to take some screenshots.</p>
  
  <p>Im using Xamarin(c#).</p>
  
  <p>I found a lot code to create some screenshots, but they were all related only to the application.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>        string path = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, " Downloads ");
  
          View v1 = Window.DecorView.RootView;
  
          v1.DrawingCacheEnabled = true;
  
          Android.Graphics.Bitmap bitmap = Android.Graphics.Bitmap.CreateBitmap(v1.GetDrawingCache(true));
  
          Java.IO.File imageFile = new Java.IO.File(path, System.Environment.TickCount + ".jpg");
          System.IO.MemoryStream bytes = new System.IO.MemoryStream();
          int quality = 100;
  
          System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);
          if (!dir.Exists)
              dir.CreateSubdirectory(path);
  
          Java.IO.FileOutputStream fo;
          imageFile.CreateNewFile();
          fo = new Java.IO.FileOutputStream(imageFile);
  
          bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, quality, bytes);
          fo.Write(bytes.ToArray());
          fo.Close();
  </code></pre>