[英]Not able to take screenshot in Android L programmatically
我正在使用Nexus 5.版本5.1.1
我想在任何給定時間以編程方式截取電話截圖。 如果解決方案特定於Nexus 5,我沒關系。
在閱讀了很多答案后,我嘗試使用screencap
以下解決方案。
問題是它創建了圖像文件,但它是空白的。
private void takeSS() {
try {
if (isExternalStorageWritable()) {
Process su = Runtime.getRuntime().exec("/system/bin/screencap -p /storage/emulated/0/img.png\n");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.flush();
su.waitFor();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(su.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
String output = line + System.getProperty("line.separator");
System.out.println(line);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
如果我從命令提示符運行,它會執行相同的命令。 請提出可能存在的問題。
PS - 我的手機扎根了。
謝謝
您是否嘗試過以su執行命令?
"/system/bin/su -c \\"/system/bin/screencap -p /storage/emulated/0/img.png\\""
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.