When I try to make a screenshot in Android Studio from some of my projects (by pressing the camera icon), I get the following message:
"Unexpected error while obtaining screenshot from device: EOF"
I can make a screenshot of the same image if I click the camera icon after opening a totally different project. Is there some corrupted file associated with the project that needs to be deleted and replaced?
I ran into this problem recently - everything had been working fine previously.
Apparently it started when I migrated to SDK 26 a few weeks ago. This fixed it for me:
- shut down Studio
- rename adb.exe in Android\sdk\platform-tools to .saf
- copy the older adb.exe from Android\android-sdk\platform-tools to Android\sdk\platform-tools
- restart Studio
So basically replace the SDK 26 adb.exe with an older version...
In my case restarting the Android Studio worked for me.
Go to File --> Invalidate Caches / Restart -> Invalidate and Restart.
But for someone who still has a problem after restarting. If you have getActivity().getWindow().addFlags(LayoutParams.FLAG_SECURE);
set (normally used to avoid screenshots), it will also prevent you from taking screenshots from Android Studio, generating the same error Unexpected Error while obtaining screenshot.
I try this way it working :
Create adb_capture.txt with content
REM ====================
REM set varible _MyTime for filename
FOR /F "tokens=1-4 delims=:." %%a IN ("%time%") DO (
SET _MyTime=%%a%%b%%c%%d
)
REM adb root
REM adb remount
adb shell screencap -p /sdcard/Download/s1.png
adb pull /sdcard/Download/s1.png
adb shell rm /sdcard/Download/s1.png
REM every file have different name by time
rename s1.png %_MyTime%.png
REM===============
Change file name to adb_capture.bat than click run which will capture phone screen