How can I take a screenshot of a selected area of phone-screen not by any program but from code?
Android – How to programmatically take a screenshot on Android
androidscreenshot
Related Topic
- Android – How to stop EditText from gaining focus at Activity startup in Android
- Android – How to open a URL in Android’s web browser from the application
- Android – unique Android device ID
- Android – ‘Context’ on Android
- Javascript – Using HTML5/Canvas/JavaScript to take in-browser screenshots
- Ios – Take screenshots in the iOS simulator
- Java – Proper use cases for Android UserManager.isUserAGoat()
Best Answer
Here is the code that allowed my screenshot to be stored on an SD card and used later for whatever your needs are:
First, you need to add a proper permission to save the file:
And this is the code (running in an Activity):
And this is how you can open the recently generated image:
If you want to use this on fragment view then use:
instead of
on takeScreenshot() function
Note:
This solution doesn't work if your dialog contains a surface view. For details please check the answer to the following question:
Android Take Screenshot of Surface View Shows Black Screen