How to take screenshot programmatically on Android? [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-17 16:26:27

问题


I want to take a fullscreen screenshot programmatically , for example, one of the android home screen or a menu. How can I get a view of the home screen in my application? I want to take it programmatically!!! It doesn't matter if it requires root mode!

Help me please and sorry for my English!


回答1:


Use following code

Bitmap bitmap;
View v1 = MyView.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);

Here MyView is the View through which we need include in screen.




回答2:


Follow the link https://code.google.com/p/android-screenshot-library/downloads/list it allows you entire screenshot of any screen not only your app

adb shell /system/bin/screencap -p /sdcard/img.png this is a shell command take screenshot simple and fast

Try this

Process sh = Runtime.getRuntime().exec("su", null,null);
   OutputStream  os = sh.getOutputStream();
   os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
            os.flush();
            os.close();
            sh.waitFor();



回答3:


In the adb shell you can use command as

adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png

I found this code on this guide on How to take a screenshot on Android.You can refer it for more details.Hope this helps.



来源:https://stackoverflow.com/questions/7514325/how-to-take-screenshot-programmatically-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!