我尝试了以下代码,但它不适用于我。
我听说过图书馆叫ASL,但我从来没有找到任何有关该图书馆的信息。
如何从服务中截取屏幕截图?我想使用后台服务。
try {
sh = Runtime.getRuntime().exec("su", null,null);
} catch (IOException e) {
e.printStackTrace();
}
OutputStream os = sh.getOutputStream();
try {
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
} catch (IOException e) {
e.printStackTrace();
}
try {
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
sh.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
Bitmap screen = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+ File.separator +"abcb");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
screen.compress(Bitmap.CompressFormat.JPEG, 15, bytes);
File f = new File(Environment.getExternalStorageDirectory()+ File.separator + timeStamp()+".jpg");
try {
f.createNewFile();
Log.e("TimeStamp : true ","file created ");
} catch (IOException e) {
e.printStackTrace();
}
FileOutputStream fo = null;
try {
fo = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
try {
fo.close();
} catch (IOException e) {
e.printStackTrace();