Android: Enable/Disable Camera programmatically - android

I want to enable/disable camera programmatically in my application.

You cannot do this from a regular app. You can do it from a device administrator, but the user has to explicitly enable it and it is only available on ICS. Here's the reference: http://developer.android.com/guide/topics/admin/device-admin.html

The OP is asking for any ideas, I got one idea and it could possibly work even without using the API provided by ICS.
for lower API version than ICS, you can Start a service that will lock the Camera when the screen is On and Release it when the Screen is Off. This is to minimize the usage of battery.
Since, only one process can use the Camera at a time, other applications like the Camera App will not be able to use the Camera.
The challenge now is how to ensure that the Service Hogging the Camera is always Running and prevent it from being uninstalled by the user.
Well, just a thought ;)

Yes, you can use DeviceAdministration class and control the camera source(block and unblock). This is a repo with an example.

Yes you can disable or enable camera but your app must device admin enabled.Following enables or disable camera:-
devicePolicyManager.setCameraDisabled(compName, isCameraOn);
**isCameraOn** is boolean true or false

Related

Android Management API Disable Camera Except For Custom App

I am exploring about using Android Management API to restrict the use of Camera for my company device. So what I need is disable all camera access except for 1 application that my company made to take picture using camera.
So what I want to ask is it possible to restrict all camera access using android management api except for 1 application that my company made?
There are some workarounds depending on the use case:
By setting the device to fully manage mode, you can disable camera access on the entire device using the policy "cameraDisabled": true. In this case, there is no way you can allow exceptions for specific custom app since the policy is device-wide and cannot be overridden with "permissionGrants": [ {object ([PermissionGrant])} ].
With that being said there are a few things we can do depending on the use case:
Making the camera app the default app that responds to android.media.action.IMAGE_CAPTURE intent using PersistentPreferredActivity
Setting up the device in kiosk mode and expose the camera app to the user.

Is there any way in Android 12 to observe Camera and Mic toggle state to prevent stream blank frame or silent audio? [duplicate]

With the new Android 12 operating system, the user now has the ability to completely disable microphone and camera usage from ALL apps. This is actually a good thing, letting users easily control privacy.
If an app starts and has permission to use the microphone and the camera AND the user has disabled all access to either of these hardware, Android 12 automatically pops up an alert asking the user to re-enable the microphone or camera, or to continue with the hardware disabled for the app.
Also, on creation, the app can simply check when starting to see if the needed hardware is enabled, and can also prompt the user further or handle the condition as the app sees fit.
But what if the user disables the microphone or camera while the app is running? I can't seem to find any interfaces for something like onMicrophoneEnabled() or even a Broadcast of such an event.
It's possible to check every time onResume() is called, but I was hoping there'd be a more elegant solution.
If anyone knows of something that my app can use to capture this when the user has made changes either way, please let me know.
After carefully reading the google docs (https://developer.android.com/training/permissions/explaining-access#toggles) on their implementation of the user enable/disable of the camera and microphone I discovered something very interesting:
Apps are explicitly forbidden from knowing if the user has done any of these actions. So of course there is no way to get notified of these changes: it is by design.
If the user turns off the camera this way, the app will still get a camera feed, but it will be black. Similarly the microphone will still work, but we'll get only silence. This is a feature--a way to ensure privacy.
The operating system will remind users that they have disabled the microphone or camera and provide a chance to re-enable the hardware, which is nice. But the app is completely in the dark (hehe).
Another way to think of it: Just like putting a piece of tape over your camera or your thumb over the microphone. Only this time it's done by the operating system. This way a spy program or some other nefarious software will still think it's working and not try to bypass or give up.
This also explains why testing during onResume() or onWindowFocusChanged() didn't work either. I was getting results that didn't align with the settings (they aligned with current permissions).
So to answer my question: There is no way to be notified. That is the point.

Is it possible, using admin priviledge or similar permission, to fully unlock the device?

Background
Smart Lock feature allows to fully unlock the device under certain conditions, such as GPS location, connected Bluetooth, etc...
The problem
I'd like to make an app that does that, with other special conditions.
Given user's approval, is it possible to completely unlock the lock screen, even if it has a password, so that the user will continue as if he unlocked the device by himself?
What I've found
I know it's probably possible using accessibility service, to mimic user actions of entering the code or drawing the pattern.
There is probably a way to temporarily disable the lock screen, by using keyguard API (written here for example), but as I've read, those are deprecated and might not work on some devices and Android versions. I guess it also requires to have a foreground service for it to continue staying on this state.
The questions
Is there a better way? Is there a way to unlock the device, just like Smart Lock feature?
If so, how?
Is it true the Keyguard API is not recommended? What is there to worry about when using it? Or maybe it's completely safe to use, and can be used to fully unlock?

Enable camera settings -- android

Is that possible to enable camera setting pragrammatically? I want to enable camera setting page programmatically and enable the user to do something from that page. I have searched so far, cant able to get proper reference.
I'm going to assume you want to open the Camera preferences activity and set location tagging on, in a similar way that Google Maps directs the user to a system preferences activity for switching on GPS. Unfortunately this isn't possible for the camera application, mainly because the camera app isn't standard across android devices.
Personally I have three camera apps on phone, not including apps like Eyem and Instagram, and I don't think this is unusual. None of them have the same activity for setting the preferences, and even the built in app doesn't have a standard preferences activity.
If you want to go down this route the best you can probably do is first check for location services being available (see How to check if Location Services are enabled? for an example if you are unsure) before invoking the intent to take the picture. Direct the user to turn them on if necessary and also, warn them that you require location tagging turned on in their camera app of choice.
if you are talking about Camera.Parameters when you say settings, yes of course you can.
All possibilities are listed here:
http://developer.android.com/reference/android/hardware/Camera.Parameters.html
You will have to write your own user interface to get the desired parameters and pass them to the camera-objekt before you start a preview.

How to Stop camera to be used . or how to make it unusable

I am working on an app, in which i need to stop some functionality of phone,
which include :
1) making or receiving phone calls,
2) use of Bluetooth or wifi,
3) Use of camera,
these feature will lock as soon as this app get installed, and will be locked until the get uninstalled, first two i have done, but i dont know how to achieve 3rd task, as i have tried locking the camera with my app, but after some time it automatically unlocked.
any clue/pointer/help will be appreaciated. Thanks
To stop camera usage I would suggest to intercept Intent.ACTION_CAMERA_BUTTON broadcast and just abortBroadcast() - in this case camera usage will be blocked.
The same approach I believe can be used for wifi and bluetooth, though I didn't check it.
Update for sure phone usage can be handled in the same manner.
Try to register broadcast receiver for BOOT_COMPLETE event, and open camera device[s] and lock() it - nobody will be able to use it until lock is given up. And I think it will stay even after your process is killed ( not sure though)
You may also try to FUBAR camera with some weird settings (I managed this sometimes, though can not explain how. - camera was unusable until reboot)

Categories

Resources