0

i have first build a facebook chat head widget and need to take the screenshots of applications and programs opened other than my program i am using for screenshot

the code i am using for saving screenshot is

 public static Bitmap getScreenShot(View view) {
        View screenView = view.getRootView();
        screenView.setDrawingCacheEnabled(true);
        Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
        screenView.setDrawingCacheEnabled(false);
        return bitmap;
    }

and the button when clicked exectues this code

   if (Xdiff < 10 && Ydiff < 10) {
                            if (isViewCollapsed()) {
                                //When user clicks on the image view of the collapsed layout,
                                //visibility of the collapsed layout will be changed to "View.GONE"
                                //and expanded view will become visible.

                                Bitmap b = null;
                                b = Screenshot.getScreenShot(v);
                                if (b != null)
                                {
                                    File saveFile = com.ocr.ocr.Screenshot.getMainDirectoryName(FloatingViewService.this);//get the path to save screenshot
                                    File file = com.ocr.ocr.Screenshot.store(b, "screenshot"  + ".jpg", saveFile);//save the screenshot to selected path
                                    shareScreenshot(file);//finally share screenshot
                                }else{


                                    Toast.makeText(getApplicationContext(), "Some error occured", Toast.LENGTH_LONG).show();
                                }

                            }
                        }

Thanks a lot Regards

Adeel Faisal
  • 23
  • 2
  • 6
  • Your code captures a "screenshot" of the supplied `View`. That will not work for capturing a screenshot of the device. You will need to use the media projection APIs on Android 5.0+, and the user will have to agree to allow your app to take screenshots. – CommonsWare Mar 12 '18 at 16:01
  • Can you please let me know any example? – Adeel Faisal Mar 12 '18 at 16:04
  • Possible duplicate of [Take a screenshot - Background Service](https://stackoverflow.com/questions/44288546/take-a-screenshot-background-service) – nima moradi Mar 12 '18 at 16:05
  • [This sample](https://github.com/commonsguy/cw-omnibus/tree/v8.10/MediaProjection/andshooter) is covered in [this chapter](https://commonsware.com/Android/previews/the-media-projection-apis) of [this book](https://commonsware.com/Android). – CommonsWare Mar 12 '18 at 16:10

0 Answers0