开发者

Capture android screen [duplicate]

开发者 https://www.devze.com 2023-01-23 03:11 出处:网络
This question already has answers here: Screen Capture in android (4 answers) Cl开发者_JS百科osed 7 years ago.
This question already has answers here: Screen Capture in android (4 answers) Cl开发者_JS百科osed 7 years ago.

How can I programmatically perform a screen capture on an Android phone?


You cannot do this from an android app except on a rooted phone, as you don't have permission to access the framebuffer device.

You can however do it over adb from the DDMS window of your development machine, as adb runs in the graphics group which has permission to the framebuffer.

If you want to do something similar in native code on a rooted device, look at the sources to the adb daemon.

EDIT: It appears this may be changing and there may be non-root capability in more recent android releases, but I'm not sure of the details.


Here's a sample of how to convert a view to a bitmap. Just grab your top view and have at it. This absolutely works and you ABSOLUTELY don't need to have a rooted device for this!

http://www.brighthub.com/mobile/google-android/articles/30676.aspx


try something like this:

View v1=childView.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm=v1.getDrawingCache();
if(bm!=null){
    //save the file
}
0

精彩评论

暂无评论...
验证码 换一张
取 消