How can I take a screenshot of a selected area of phone-screen not by any program but from code?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I have created a simple library that takes a screenshot from a
View
and either gives you a Bitmap object or saves it directly to any path you wanthttps://github.com/abdallahalaraby/Blink
Just extending taraloca's answer. You must add followings lines to make it work. I have made the image name static. Please ensure you use taraloca's timestamp variable incase you need dynamic image name.
And in the AndroidManifest.xml file following entries are must:
No root permission or no big coding is required for this method.
On adb shell using below command you can take screen shot.
This command does not required any root permission so same you can perform from java code of android application also.
More about keyevent code in android see http://developer.android.com/reference/android/view/KeyEvent.html
Here we have used. KEYCODE_SYSRQ its value is 120 and used for System Request / Print Screen key.
As CJBS said, The output picture will be saved in /sdcard/Pictures/Screenshots
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
You can try the following library: http://code.google.com/p/android-screenshot-library/ Android Screenshot Library (ASL) enables to programmatically capture screenshots from Android devices without requirement of having root access privileges. Instead, ASL utilizes a native service running in the background, started via the Android Debug Bridge (ADB) once per device boot.
if you want to capture a view or layout like RelativeLayout or LinearLayout etc. just use the code :
now you can save this bitmap on device storage by :