Take screenshot of current Activity from a Service in Android - android

I want to take a screenshot of an Activity of my application, but I do not have the code of that activity (only its class file since it is imported from an external API) so am not able to modify the UI and add an event which will help me taking the screenshot.
Thus, I thought about using a background Service which can detect all application's activities and to take the screenshot if matching the wanted activity with some condition.
I have browsed many question/answers about the subject, but nothing matched what I want to do.
So, I will be very grateful for any help, or suggestion about this.
Thank you.

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!)

Starting a function in the onCreate (without a button click)?

I know this might be a basic question, but I am a beginner and I haven't been able to find an answer.
I would like to know, if it is possible to trigger some function/action while creating an activity. eg. trigger a void without user intervention, start an animation automatically after an Activity is created etc.(at the moment I am trying to trigger an animation without a button click, but this question is general and not specific code related).
I know how to bind an action to a button click and every resource I have found is doing that, I haven't, however, been able to start an animation or a void without it and I am not sure if it is possible. (I have tried using Handler, it worked but prevented the rest of the code being executed - I might have done it wrong, though as I really am a beginner)
so my question(s): Is it possible to trigger a function/animation without user intervention(click)?
If so, where can I find some resources to read about it? (I tried reading Android documentation already)
Thank you very much and I apologize if the question is too simple, I know it might be.
Please have a look at this photo.
It clearly explains the lifecycle of Android activity.
To answer your question, yes, it is possible to trigger a function/animation without user intervention(click). You have to call the function from onStart() activity.

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 screen capture without layout root view

Actually in android mobiles when we press the home button and the side button at a time we can make a screenshot. which event is running at the time of pressing?
In the camera event we fire android.provider.MediaStore.ACTION_IMAGE_CAPTURE.
Posts about how to make a screenshot:
This: screenshot in android
or this: How to programmatically take a screenshot in Android?
or maybe this: https://stackoverflow.com/a/10482368/1164919
But i did not find anything about some kind of provider as you describe in your post.
It looks like there is a dedicated service running from android 4.0 and up which helps to take screenshots by the way you have mentioned here.
But I am not aware of how it happens in the previous versions of android.
Here is a link to the Service TakeScreenshotService. When you look into it you will be able to see another class which actually is responsible for capturing the Screenshot and storing it. And here is the link to the class GlobalScreenshot.

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.

Categories

Resources