Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 程序中截屏 #2

Open
Yhzhtk opened this issue Sep 12, 2013 · 1 comment
Open

Android 程序中截屏 #2

Yhzhtk opened this issue Sep 12, 2013 · 1 comment
Labels

Comments

@Yhzhtk
Copy link
Owner

Yhzhtk commented Sep 12, 2013

 /**
 * 获取屏幕截图
 * 
 * @return 截图路径
 */
public static String screenCap() {
    try {
        Process sh = Runtime.getRuntime().exec("su", null, null);
        OutputStream os = sh.getOutputStream();
        os.write("/system/bin/screencap -p /sdcard/screen.png".getBytes());
        os.flush();
        os.close();
        sh.waitFor();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return screenName;
}
@Yhzhtk
Copy link
Owner Author

Yhzhtk commented Sep 12, 2013

使用系统命令 /system/bin/screencap -p filename 进行截屏并保存到filename。以上代码是在android中启动系统进程运行命令完成截屏操作。

另外还有一个命令 /system/bin/screenshot, 这个命令保存的图片会错位,不知道什么原因。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant