Detect when another app tries to use the camera - android

Our app runs as a background service, continuously getting the images from the frontal camera and then doing things with the images. However, when the user tries to open another app that uses the camera, two things happen: either the new app crashes and ours continues, or our crashes and the new one gets access to the camera.
Now, if our app loses control over the camera, there's an exception that we can catch, and we can then start trying to access it until we get access and things go back to normal.
The problem is when the other apps crash because of ours. Is there any way to detect this, so we can pause our app until we can access the camera again?

This happens because camera is an exclusive resource.
I recommend you to read the Camera documentation, which says:
If your application does not properly release the camera, all
subsequent attempts to access the camera, including those by your own
application, will fail and may cause your or other applications to be
shut down.

Unfortunately, Camera API or Android SDK in general don't provide this kind of info. The good news is that gradually, more new devices let you open the front-facing and the rear-facing cameras independently. This could reduce the probability of a clash.
From your description, it may be legitimate to crash the applications that compete with yours over access to camera, but, jokes aside, there is nothing you can do about it. It's their fault that they don't check the RuntimeException correctly.
Android has recently tightened the isolation between apps, so it may be impossible to track which applications are started (see App to monitor other apps on android), unless your app has system privileges.

Related

How do I open an app Based on an external Event

Use case: I have security cameras around my home (on zoneminder). When an event is triggered (someone walks by the camera) I want to have some screen nearby the door and ideally push a notification to devices (hopefully android tablets) to display the camera view on all these connected devices.
I'm happy developing my own app if necessary (even better if such an app already exists). But does Android support this functionality to allow an app to open based on an external event (some message to the app)? I've personally never seen it (phonecall is the one exception). I'm sure listening for events is easy, but I can see there being a rule not to allow apps to 'force open' in this way.
If there is a way, if you could point me to the class that would support this I would appreciate it. Thanks!
(If you have any other solutions for my use case, I'd be happy to hear them. Unfortunately, I'd like these tablets to run other apps too, so keeping the 'camera app' open constantly isn't really a solution for me.)

Launch camera to take photo in countdown mode

How can I launch to the device camera, in built-in countdown mode, configure it to 10s and take a photo?
Without user interaction.
The user should not press the capture button. It should start programmatically.
Thanks.
First, the "device camera" does not necessarily have a "built-in countdown mode". There are thousands of Android device models, with dozens (if not hundreds) of pre-installed camera apps. None have to have this feature. Similarly, there are hundreds of camera apps available on the Play Store, and none of them have to have this feature.
Second, even if a camera app has this feature, there is no requirement that it expose an API for third-party developers to invoke this feature.
Third, even if a camera app has this feature and exposes an API for it, there is no standards for this API.
You are welcome to contact the developers of various camera apps and see if they have the feature and, if so, if they have an API for third-party developers to invoke it.

Opening of Front Camera and Back Camera simultaneously?

How can i open both front camera and back camera at the same time in android? Is it possible?
I have tried tried but my application stops unfortunately.
Please Help..
On some devices, e.g. based on Snapdragon 805, you simply can. In other cases, the manufacturer chose to block the naïve approach, but the native camera app knows how to do it, and, with some reverse engineering effort, you can reproduce their approach (I had partial success with Samsung S4 before I lost interest in that project).
But on most of available phones, there is a physical restriction: the two cameras share the same bus, and cannot be opened simultaneously, no matter how skillful you are in software.

Detect screenshot attempts on Android 4.0+

I am developing an Android application that places a high priority on protecting the user's data, to the point of storing nothing in persistent memory on the local device.
To further protect user data, we want to make a web-service call to our server whenever someone attempts to take a screenshot of the active application.
Solutions that I have seen so far include this snippet intended to prevent the screenshot from being taken and throwing a screenshot failure message in a Toast at the user. Another approach I was considering was listening for the combination of Volume Down and Power button that some devices use to take screenshots (though devices such as the Samsung S4 deviate from this method). My last resort was going to use a FileObserver in the location of the screenshot Gallery for changes while the app is running, but that also seems like a sub-optimal solution and introduces a Permission request that I'd rather not have. I also can't be sure of the file destination for the images.
I believe the Snapchat app is able to alert participants when a remote user attempts to take a screenshot. Do you have any suggestions on how this feature might be implemented, short of rooting the device? Non-official methods are welcome as well.
FLAG_SECURE is probably the best way to avoid screenshots in a window, but as some commenters say here it has some workarounds.
Maybe this answer solves the question about how do they do it in Snapchat to detect when a screenshot has been taken.

How to prevent Android from killing my Unity app?

I'm developing an augmented reality app with Unity where users can shoot a photo with their mobile device to add 3D objects on it. The problem is that on Android, when the user chooses to shoot a photo from my app, the app is put on the background and often closed instead of being kept in memory to handle the photo taken. I know it is because of Android killing apps to free ram.. But is there a way to prevent the killing of my app ? Even on Ipad 2 with its 512Mo of ram IOS doesn't do this brutal killing thing : after the shooting it goes back smoothly to the app. Whereas Android does it with my 1Go of ram phone.
Also I do not want my app being killed and restarted by a service to handle the photo because it is pretty heavy to load and so really far from starting instantly.
Application.runInBackground is disabled on mobile platforms and therefore Unity cannot guarantee that your game/app is kept running. This behaviour is normal as the OS kills activities as needed. Sadly Android is resource hungry and therefore apps that stay in the background on iOs might be killed on Android, even with better hardware.
As hinted in this thread you have a few options: use states to handle pause/resume, create a service that will keep running in the background (it will have to be created outside of Unity either via a plugin or in eclipse) and/or use Android's intents mechanism.

Categories

Resources