截取屏幕(需要root权限)

3

我有一段代码,可以在已root的设备上截取任意屏幕的截图,但是似乎不起作用!我的设备使用的是2.3.7版本的安卓系统,我不知道是否可以在这种情况下使用screencap。如果可以使用,我是否需要下载任何c或cpp文件?

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

我添加了这个检查目录的代码来检查是否已经拍摄了屏幕截图:

File f = new File(Environment.getExternalStorageDirectory()+ "/img.png");
            if(f.isDirectory() && f.isDirectory()) {
                Toast.makeText(getApplicationContext(), "Screenshot taked", 0).show();
            }else{
                Toast.makeText(getApplicationContext(), "Screenshot not taked", 0).show();
            }
1个回答

0

使用Root Explorer,我进入了System/bin目录,但是文件screencap并不存在,因此我认为这个Android版本(2.3.7)不支持screencap。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接