How to take a screen shot in android - android

I want to take a screen shot in android irrespective of the application and without rooting the phone. I have seen into the previous thread link
I followed this instructions but they are specific to one application. And we need to change the layout file of every application.
I also came across the link which is a library. One thing which is not clear to me in this is that whether the manifest.xml file should be changed for every application.
Can you please let me know if any other ways are possible? I know this is a security issue but if the application doesnt mind I need to take the screen shots.
Thanks.

if you don't need the status bar (or keyboard) you can do this in your activity:
View root = findViewById(android.R.id.content);
root.setDrawingCacheEnabled(true);
Bitmap bm = Bitmap.createBitmap(root.getDrawingCache());
root.setDrawingCacheEnabled(false);
Completely untested but it should work.
After seeing your comment about taking screenshots of other applications I do not believe that what you want is possible without rooting the phone.

Related

Take screenshots from other apps as image source

I'd like to offer an app to modify images. In order to have the user give an easy access to the that feature, it would be the easiest solution to just let him directly take a screenshot to have the source picture taken or respond to a screenshot event and access the latest screenshot.
Unfortunately it seems to be a problem, since an app or even a service from the app runs in background cannot easily react to events and I haven't found any solution that would go only little close to that kind of thing.
So my questions are (lets assume all necessary permissions are given from the user):
Is there a possibility to register my app as kind of standard screenshot app (or additional screenshot app triggered by another key combination of the device) and how ;-)
Can an app stay in a state to notice if a screenshot is taken and
can access it?
If not: Any ideas for an workaround other than let the user select a taken picture, which is rather kind of roundabout and annoying?
Any hints are very welcome! Thank you in advance!
(Since I had a misleading headline, I reposted this question - sorry!)

Android - Take a "Screenshot" of an App Running in the Background

I have read plenty of questions that deal with an app taking screenshot of the current users screen while the app runs in the background, but have not seen many articles that deal with the app taking a "screenshot" of itself while it runs in the background.
I would like this to be able to be done without having to root the phone in any way as I would like the app I make be available to everyone(rooting is probably not involved in this solution, but just throwing that out there).
The end goal of the app is for the app be able to take a screenshot of itself and save that screenshot as the users background wallpaper. There are several other features I would like to add, but I would just want to know, is this even possible? If this is, could anyone show me some starter code or link me to some?If this question has been asked before, please let me know, otherwise, any and all help is appreciated. Thank you!
Firstly, I am not really sure if I understand your requirement correctly. Ideally when the app is in background, its state when it went to the background and while it is in background will remain the same. So you can take a screenshot of your app, when the app is just going in background, which can be handled in your onPause() of the activity.
To take screenshot of your app, place the entire layout in a ViewGroup and then use the following code.
parentLayout = (RelativeLayout)findViewById(R.id.parentLayout);
parentLayout.setDrawingCacheEnabled(true);
parentLayout.buildDrawingCache();
And when you want to take a screenshot, get the screenshot in the Bitmap by using
bitmap = parentLayout.getDrawingCache();
The above line should be in your onPause() thats when the app goes in background. Or you could also trigger it when your app is in background, and see if it is captured. I'm not really sure how it will work in the latter scenario.

Android Taking Screenshots of device

First of all yes i know its not possible to code this in my app without root permission.
I need to take screen shot even outside my app without root.
I just need to know if i can request Android os for me to take a screen shot for me via some intent.
I wont have much control over it but is it possible?
Currently do not exists intent for this.
You can see the documentation of Intents broadcast by the system
You can take a screenshot in an instrumented test ("androidTest") using https://developer.android.com/reference/android/app/UiAutomation#takeScreenshot() for example:
InstrumentationRegistry.getInstrumentation().getUiAutomation().takeScreenshot();
This works outside the context of the app. Not sure if it serves your particular purpose, but it's an option.

to get a current screen view from my own application

I am running one external application from my own application and when this application opens, i want to get a view of that external application in my own application. So that i can capture a screenshot of it. Please help me in this.
I dont think thats possible. The communication between applications or even activities is limited to passing data to each other through intents. I don't think sharing references to objects across applications is possible. Please correct me.
Such a thing would be possible if they allowed you to launch an external application in your own window.
I did some search and it is quite likely it may not be possible, however I have found a possible way. Take a look at this link, which states that
Or If you want to take a ScreenShot of your current device screen (any
application) then you have to root permission, and read framebuffer
for that which will give raw data of current screen then convert it to
bitmap or any picture file you can do it in your service.
Which means that whenever your application starts an application you will need to create a service that reads the framebiffer, but if an activity is used for taking the screenshot then it will not be useful because the screenshot will then be of that activity.
See this and this, these links are related to your question as well. And see if it works.
Hope this helps.

how to take android user homepage screenshot programmatically?

I'd like to take the Screenshot of user homepage Could you please guide me how I could do that Currently I am using
LinearLayout linearLayout = (LinearLayout )findViewById(R.id.layout);
linearLayout.setDrawingCacheEnabled(true);
Bitmap bitmap= linearLayout.getDrawingCache();
Its working for my views but how I can find the Homepage view and take the screenShot of User homepage.
If by Homepage you mean the rootview of the screen then
getWindow().getDecorView().findViewById(android.R.id.content)
see question 4486034
Fortunately, this is not possible, for obvious security and privacy reasons, except perhaps on rooted devices.
I believe you can only do this on rooted devices using adb or something along those lines, Ive seen it done before, just not sure how, try finding out how to use ddms using an app on the phone

Categories

Resources