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
You can try to do something like this,
Getting a bitmap cache from a layout or a view by doing something like First you gotta
setDrawingCacheEnabled
to a layout(a linearlayout or relativelayout, or a view)then
Then you do whatever you want with the bitmap. Either turning it into an image file, or send the bitmap's uri to somewhere else.
The parameter view is the root layout object.
Call this method, passing in the outer most ViewGroup that you want a screen shot of:
If you want to take screenshot from
fragment
than follow this:Override
onCreateView()
:Logic for taking screenshot:
method
shareScreenShotM)()
:method takeScreenShot():
method savePic():
For activity you can simply use
View v1 = getWindow().getDecorView().getRootView();
instead ofmView
Based on the answer of @JustinMorris above and @NiravDangi here https://stackoverflow.com/a/8504958/2232148 we must take the background and foreground of a view and assemble them like this:
The quality parameter takes a constant of Bitmap.Config, typically either
Bitmap.Config.RGB_565
orBitmap.Config.ARGB_8888
.For system applications only!
Note: System applications don't need to run "su" to execute this command.