I am using the Android Camera2 API to take photos for an app and I can't get the flash to work properly on most Samsung Galaxy devices (galaxy s6 edge, galaxy s7, galaxy j7). I believe I have implemented the flash logic properly because Google's Camera app that used to be on the Play Store also exhibits the same behaviors. Also the galaxy s8 seems to work with the flash pretty well (although results definitely have inconsistent lighting)
The issue with the galaxy j7 is that when I take a picture with flash (either with flash locked on or with auto flash in a scene that requires flash) the flash will stay on for a long time, the preview will lock, and then after maybe 7 seconds the image will take, and the flash is not a part of the image.
I have the following method handling flash modes:
private void setAutoFlash(CaptureRequest.Builder requestBuilder)
{
switch (mFlashState)
{
case FLASH_STATE_AUTO:
requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
//requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
break;
case FLASH_STATE_ON:
requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
//requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_SINGLE);
break;
case FLASH_STATE_OFF:
requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
//requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
break;
}
}
This flash logic is called every time a CaptureRequest.Builder is needed
The 3 commented out lines are something else I read that was suggested to help flash work properly for me, but it doesn't seem to do anything
Samsung has their own camera API (http://developer.samsung.com/galaxy/camera)
but I read that it is just a wrapper over Camera2 and I am worried that their API won't even fix my issue.
Additional Information:
I have tried some camera apps from the play store, some work and others don't.
ZCamera works fine with flash, which made me think they use Samsungs camera API to get it working, but then I noticed that ZCamera's touch metering doesn't work on Samsung devices which is another issue I came across while debugging my Camera2 implementation.
Flash seems to work fine if I stick with the deprecated Camera API
Any help on how to accomplish a working flash would be greatly appreciated
Actually using camera2 API is very special in android devices. Some methods may not be implemented. For example: this and this.
For the others, proper flash modes should be set depends on the other properties.
This code works for me in most Samsung devices that support camera2API:
if (mIsFlashSupported) {
switch (mFlashMode) {
case FLASH_MODE_ON:
requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_SINGLE);
requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_FLUORESCENT);
break;
case FLASH_MODE_OFF:
requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);
requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_DAYLIGHT);
break;
case FLASH_MODE_AUTO:
default:
requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH);
requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_SINGLE);
requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_DAYLIGHT);
break;
}
}
After working at this on and off for a bit I realized a few things. I mentioned that ZCamera (from the play store) works with flash, and I thought they accomplished this by using the Samsung SDK. I checked the app and it does not use the Samsung SDK.
I also incorporated the Samsung SDK into my app and that didn't change anything. The Samsung SDK is really just a wrapper around google's camera 2 so you can add some Samsung specific features, adding it to your project wont fix any Samsung compatibilities.
What I finally realized was that the touch metering flow I had programmed myself (touch to focus/then take a photo) worked very differently than my logic that ran when we take a photo without touch to focus. The regular photo logic was borrowed from googles camera2 api example code and it wasnt working propery.
The trick to get the flash to fire on Samsung devices (or at least what worked for me) was to first trigger a check for AE levels, and once that converges then start the auto focus trigger. If flash is turned on this will fire the flash to check AE levels and to focus, and then fire the flash once more to take the photo
My application takes a photo every 5 seconds. I (1) select the camera, (2) acquirer a session and then with each loop I (3) create a Capture request in which I set the Flash Mode and call the capture method on the session.
I have no issues with my Samsung SM-G550T (Android version 6.01), but I was having some issues with the Flash Mode on my Moto G4 (Android version 7.0). I got both phones to Flash, but only with this setting:
CaptureRequest.Builder requestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_SINGLE);
I am presently having an issue with a LG device (M210N) (Android version 7.0). Using the settings I stated above I get the device to flash just once. If I completely re-initialize the camera (as described above) the device will flash again only once.
If I add the CONTROL_AE_MODE_ON_ALWAYS_FLASH setting to the above requestBuilder, then the LG does not flash at all. So I had to remove that flag.
I have tried many different additional settings and combination for settings and none of them have eliminated this issue. I wonder how many devices are affected by this issue.
Related
We have an Android application which works well on Android 4.1+ till Android 7.
Only in Android 5.0 and 5.1 we experience a difficult problem (on all devices + emulators).
The icons we use in our application turn completely black after hiding the software keyboard (when you are finished typing something in a textbox).
They stay black, even after restarting the application.
But after restarting the device (or closing the application by taskmanager), the icons are back normal (till you hide the keyboard again).
I don't find anything unusual in the code or icons and since it works in Android 4,6,7 it seems related to just Android 5.
Does someone has some idea at what the cause could be?
Disabling hardware-acceleration didn't have any effect.
This problem mainly occurs if you are using some other format of images like jpeg , use only png images also you might want to have a look at this answer
I've created a simple Android flashlight app that seems to be working on any Samsung device that I've tried it on but it doesn't seem to work with the LG G series phones. I've tested it on the LG G3, G4 and G5.
The app loads up the mainActivity perfectly fine, but when the flashlight button is clicked, nothing happens. I've plugged it in to see if there's some sort of error message that comes up when I attempt to use the flashlight, but no error occurs.
Is this a common problem between device manufacturers? I've done a bit of research and from what I've gathered as long as I code my app properly towards each Android OS, I shouldn't have a problem.
I've had some LG devices work, while others simply don't. Both phones have been on the same Android Version and on the same network. Anyone else experience this?
EDIT
I learned that you have to setPreviewTexture(0) on some phones in order for the app to turn the torch on properly. However, now I'm running into the issue of the app lagging when trying to use it with burst mode.
Hi I wrote a program with Google Maps API V2 .
this program run on emulator But when run on real devices I see only white screen whit Google logo and Zoom buttons .
What is the problem ?
my phone is Samsung galaxy s2.
thanks ;)
Since the Google Maps app does not work on the device, your app will suffer from the same problems. That could be a problem with your ability to access the Google Maps servers (e.g., firewall issues), or it could be a problem with the device (e.g., flawed ROM mod).
Regardless, until you get Google's own Maps app to work on your device, there is little you are likely to be able to do to help your own app.
I'm trying to work with Android's camera API 2, and I had a bug which I wasn't able to fix.
The function getCameraIdList() returns an empty array for some reason, although I do have 2 working cameras on my emulator (I checked it using the Android camera app).
I am working on an emulated device with the following details:
Device: Nexus S
API level: androd 4.4.2, API level 19
CPU: intel atom x86
front & back camera are emulated
what do you think?
attached is the code.
private CameraManager mManager;
private String[] mCameraIds;
mManager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
mCameraIds = mManager.getCameraIdList();
The function getCameraIdList works only from version 21 of Android API
Here are four things that might get the app to start working again. One of these four have always done the trick for me when the I get the error.
Switch to another app and then back to the camera app.
Hit the back button to exit the camera app and then tap to open it again. This has the least success rate, to be honest, but it does work and it’s the quickest solution.
Exit all apps that might be using the camera.
Go to Settings>Battery and check if mm-qcamera-daemon is running. Exit it and launch the app again to see if the camera connects.
Exit the app and relaunch it. This works most times.
If it doesn’t try to force stop the app and clear the cache. The measures sound drastic but it has a high success rate.
If all else fails, restart your phone.
Exit every app that’s running before restart it. I found this to work when nothing else would and so far the error hasn’t popped up again.
Is it possible to simulate or test Touchscreen input with the Android Emulator?
I'm working on a project which needs to support touchscreen input, but I don't have an Android phone myself. However if I could use my mouse to simulate/test touchscreen support in my app, it would be perfect.
Yes, you can implement the OnTouchListener and then on the emulator you can use your mouse.
A small tutorial here
http://www.mybringback.com/tutorial-series/3279/android-the-basics-32-androids-ontouchlistener-and-motionevent/
It's theoreticaly possible. But to date multitouch support requires a real Android 4.0 device to send multitouch input to the emulator. However, in this case you don't need the emulator and can test directly on the physical device.
You can read latest information about multitouch support here.