Take ScreenShot of Visible screen Android - android

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();

Related

Run shell command("su") for current screen View

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/

Android Take Screenshot rooted phone

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?

Android share display on another devices

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.

Take really quick screenshots of Android Phone programmatically

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?

How to take screenshot programmatically on Android? [duplicate]

This question already has answers here:
How to programmatically take a screenshot on Android?
(26 answers)
Closed 8 years ago.
I want to take a fullscreen screenshot programmatically ,
for example, one of the android home screen or a menu.
How can I get a view of the home screen in my application?
I want to take it programmatically!!!
It doesn't matter if it requires root mode!
Help me please and sorry for my English!
Use following code
Bitmap bitmap;
View v1 = MyView.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
Here MyView is the View through which we need include in screen.
Follow the link
https://code.google.com/p/android-screenshot-library/downloads/list
it allows you entire screenshot of any screen not only your app
adb shell /system/bin/screencap -p /sdcard/img.png
this is a shell command take screenshot simple and fast
Try this
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();
In the adb shell you can use command as
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png
I found this code on this guide on How to take a screenshot on Android.You can refer it for more details.Hope this helps.

Categories

Resources