I am taking screenshots of an Android phone from my application by this code
java.lang.Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("cat /dev/graphics/fb0 > " + raw + "\n");
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();
But when I put this in a service, and try to run infinitely, I get atmost 2 screenshots.
Is there a way to take screenshots really quick? Like 15-20 in a second using ANY way possible?
EDIT : I try to convert them to video later. Any way to make video without dumping it to the file altogether?
Related
I want to take screen shot of any visible screen from background. I don't want to be dependent on activity context. Whatever screen I open in my device like browser or any social app I just want to take screenshot of that.
I tried different approaches but it is depended on activity and we can only take screenshot of current App.
Any help would be appreciated. thanks
Works only for rooted diveces
Process sh = Runtime.getRuntime().exec("su", null,null);
OutputStream os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
os.flush();
os.close();
sh.waitFor();
I'm working on a rooted android device. I'm trying to capture the screen and store the result in Bitmap for later usage.
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath();
path += "/img.png";
Process sh = Runtime.getRuntime().exec("su", null,null);
OutputStream os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + path).getBytes("ASCII"));
os.flush();
os.close();
sh.waitFor();
final Bitmap x = BitmapFactory.decodeFile(path);
What I'm doing here is naming a path for a new image and capturing the screen using the command /system/bin/screencap -p FILEPATH. Then I read the image I stored in that file and use it in the bitmap.
My problem with my current code is that it's slow(not suitable for a real-time application). I'm now trying to make it faster. Instead of saving the captured picture into file and then reading it again from the program, I want to read it directly from the result of Runtime.getRuntime().exec(...)
In the description of the command screencap, I found that I can use it without specifying the output file name, and in this case the results will be printed to stdout.
I tried several codes to read the result byte array to use it directly in my code
final Bitmap x = BitmapFactory.decodeByteArray(resultArrayByte, 0, resultArrayByte.length);
but none of the codes worked with me.
How can I use sh's input/output streams to get the result byte array directly without saving the output into a file then loading it again?
Take a Look here, in this link you can find a library called ASL
a lot of questions in this post, i'm confused :)
i hope this link is useful for your requirements.
I am trying to execute a shell script from my Android application to get current screen view.
I have got following code working properly on rooted devices only.
Process sh = null;
try
{
Thread thread=new Thread(new Threadcalling ());
thread.start();
sh = Runtime.getRuntime().exec("su");
OutputStream os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
os.flush();
os.close();
sh.waitFor();
}
catch (Exception e){}
What modification should I do to get screen View on non-rooted devices.
Any help will be appreciated. Thank you.
You cannot do this for non-rooted devices, in other words, you app has to be a system app to access other system apps.
EDIT: Maybe this link may help you:
https://code.google.com/p/android-screenshot-library/
I am capturing screenshot from my android rooted device using
Process process = Runtime.getRuntime().exec("su", null,null);
OutputStream os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
os.flush();
os.close();
process.waitFor();
It works fine as long as the content on the screen is static (image etc). But when I try to take a screenshot when a video is playing, then the screenshot shows a black screen. Is there any other way to do this?
i'm working on share the tablet display with more than one table (all rooted) connected through WiFi , i'm using the following approach (all inside one thread) :
1- i take a screen shot.
Process sh = Runtime.getRuntime().exec("su", null,null);
OutputStream os = sh.getOutputStream();
os.write(("/system/bin/screencap -P " + "/sdcard/test/img.png").getBytes("ASCII"));
os.flush();
os.close();
sh.waitFor();
2- compress the screen shot image.
Bitmap mBitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getPath() + "/test/img.png");
OutputStream outputStream = null;
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/test/img2.png");
outputStream = new FileOutputStream(file);
mBitmap.compress(Bitmap.CompressFormat.JPEG, 15, outputStream);
outputStream.flush();
outputStream.close();
3- open socket and send the compressed image to another tablet.
this is working but my problem is the viewing delay in the other tablet it took 4-5 sec to refresh the new display , is there any better approach to have it real time display?
Unfotrtunately, this function will take long time. It is linked with process lifecycle, IPC and the slow file system. You need to have a look at this library or the source code of /system/bin/screenshot util. You have to reuse native(c-language) functions from sources, and it is not a trivial task.