Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Take a screenshot from service

dmytrivvvvdmytrivvvv USMember ✭✭
edited March 2017 in Xamarin.Android

I need to take a screenshot of the whole device screen, when my app is in background. I think i should start a service and make it to take a screenshots, but i don't know is it possible...
Is any way how to do it???

Answers

  • Jay_UKJay_UK GBMember ✭✭

    Did you manage to solve this?

  • ChristChrist BEMember ✭✭✭

    Hello all,
    first , you need to make a broadcast who is call every x minutes for example
    after, you can do this :

    `
    public void takeScreenShot()
    {
    string path = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, " FOLDER NAME ");

            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();
    
            //
           //openScreenshot(imageFile);
        }
    

    `

Sign In or Register to comment.