I am working on custom camera and using deprecated Camera api's instead of Camera2 api's in Android L but I am facing lots issues in preview. One of them is, It is showing dark preview and another problem is setSceneMode and setColorEffects making no effect. Please let me know the workaround if any one out there used deprecated camera api's in v21.
Setting a high FPS which may produce a dark preview in some devices, because a high FPS lowers the exposure compensation. Setting it to a variable range instead of a fixed one can solve the problem for the devices that present such issue.
A device may return a set of supported ranges such as for example: [10-15, 15-30, 30-30]. In this example you would pick up any of the variable ones, and avoid the fixed one [30-30]. Note that fixed ranges are meant to be for video only.
Turns out Camera.Parameters is deprecated.
This class was deprecated in API level 21.
We recommend using the new android.hardware.camera2 API for new applications.
Android Developer - Camera.Parameters
You should use this instead for devices with API level > 21:
Android Developer - android.hardware.camera2
Related
I've been working on a customized camera app, it only changes the layout of how the camera is shown but it doesn't change any core feature of the camera.
As I searched, I found these libraries: hardware.camera2 , hardware.camera and cameraX.
And my app should work properly on minSdk 17. so my question is: is camera api deprecated so I can use camera2 on my app?
As I saw in documents you could only use camera2 with cameraManager on API 21 and higher.
Can anyone help me with what library I should use and how I could implement it?
hardware.camera (also known as Camera1) was deprecated in API level 21.
hardware.camera2 (also known as Camera2) was introduced in API level 21.
camerax is part of the Jetpack suite of libraries, and is built on top on Camera2, so is backward compatible to API level 21.
If your app has a minSdk version of 17, you can define a single Camera interface to use in your app, then provide 2 implementations for it using camera1 on API levels below 21, and CameraX/Camera2 on API levels starting at 21. Whether you choose Camera2 or CameraX depends mostly on your camera features. CameraX provides fairly easy to use APIs for preview, image analysis and image capture, and resolves device compatibility issues. You can take a look at its official documentation to see whether it meets your app's requirements, if it does, you can get started on it with this codelab. Camera2 provides a more fine grained control over the camera, but come with more complexity to handle it, you can take a look at what it provides through its official documentation.
I am trying to figure out the limitations of using camera2 with devices that have hardware level support LEGACY. From the official docs for android camera2 api:
LEGACY: These devices expose capabilities to apps through the Camera API2 interfaces that are approximately the same capabilities as those exposed to apps through the Camera API1 interfaces. The legacy frameworks code conceptually translates Camera API2 calls into Camera API1 calls; legacy devices do not support Camera API2 features such as per-frame controls.
I have found this to be false... In fact I expected that sensor orientation obtained through Camera.CameraInfo camInfo -> camInfo.orientation (docs) would be the same as cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION) (docs)
However it is not the case!
Camera API 1 returns an orientation angle of 90°
Camera API 2 returns an orientation angle of 270°
Notice that this is quite different! Landscape orientation != inverse landscape orientation! For example it would completely break the Matrix transformation from the screen preview coordinates to the camera sensor space.
Am I missing something? Is this intended behaviour?
I am using a Xiaomi Redmi 5 plus with Android 8.1 (is this a manufacturer issue?)
Thanks
If the two queries apply to the same camera, this is definitely a bug, and Xiaomi is responsible. Bugs do happen even on mainstream devices, and the camera API adaptation layers tend to be more buggy than other APIs.
You may find that for LEGACY devices, camera2 layer introduces extra overhead, and vice versa. You get best performance if you work trhough the deprecated Camera API for LEGACY devices, and through the camera2 API for other devices. I know it's painful to support two versions of your code, but when you need to utilize the device in the best way, you have to pay this price.
I'm building an App which is similar to social media where people can share photos and videos like Instagram. That's why Camera is very important for my app. Now camera2 API is confusing me. I want to run my app on API level 11+ . I know camera2 is only available in API level 21+ So, I need to design two APIs one(camera) for older version and second(camera2) for higher version. Problem is that I just started to learn Android and I do not know what is the main difference between these two APIs.
What main features are available in Camera2 API ?
Or Is there any drawback of Old Camera API ?
I need three things in my App.
1- Simple capture photos
2- Burst pictures (To create GIF Image)
3- Simple video recording.
Which Camera API is good for me ?
The old camera API will work fine for #1 and #3; if you're OK with video-resolution GIFs, you can do #2 as well.
You'll need camera2 (and then devices that support fast, full-resolution capture - see the BURST_CAPTURE capability, or any device that supports the FULL hardware level.), if you want bursts at resolutions above ~1080p.
You can probably start with the CameraView unofficial support library, and modify it as needed. It has support for both APIs, selected based on API level of the device.
I need to create a custom camera in Android that supports both higher and lower version.I am new to android.I have research a lot I have the code ready for hardware camera i.e. for the api less than 21.But I am finding hard time searching the code that supports camera hardware 2.
The old deprecated camera API still works on Android 21 and above. But you are right, using the new API is preferable, and gives you more options and better performance.
You can start with the official Camera2Basic sample.
I'm working on an Android app that shows a camera preview. Ideally I'd like the app to work in portrait mode, which means I need to deal with rotation of the camera preview image.
I only need to support API level 8 (Android version 2.2) and up, so I can use Camera.setDisplayOrientation to set the orientation, and the API docs for that method include a setDisplayOrientation function that does what I want. The only problem is that it uses the API Level 9 Camera.CameraInfo to get the orientation of the camera with respect to the device (presumably to deal with landscape vs portrait devices).
So is it safe to assume that I can do setDisplayOrientation(90) for all level 8 devices and just use CameraInfo.orientation for newer devices?
I have tried the following on an HTC Evo Shift with a project set to API8 (worked great):
Configuration cfg = mContext.getResources().getConfiguration();
if (cfg.orientation == Configuration.ORIENTATION_PORTRAIT) {
mCamera.setDisplayOrientation(90);
}
As a follow up for anyone else finding this - I didn't find a definitive answer on this, so I did as I suggested above (setDisplayOrientation(90)) for 2.2 devices and released the app. It's had about 70,000 downloads and no reports of the camera display being wrongly rotated by 90 degrees, so it looks like this is a reasonable solution.
I'm posting the link to Android's developers help in the Camera matter:
http://developer.android.com/guide/topics/media/camera.html
About your question in specific, i took a look at the API and i guess, since the surfaceChanged method is called every time a change in surface is made and the equipment have only 2 position, you are probably right, since u implement the corrected methods in the surfaceChanged method. Try to implement it and if you can't get it to work post the problem and i'll try to help more.