I tried the following code but it is not working for me.
I heard about Library call ASL, but I never found anything about that library.
How can I take a screenshot from the service ? I want to take it using a background service.
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();