How to programmatically clear the Camera cache in Android? - java

I have an issue with Samsung Galaxy tablets. When my application triggers the camera flash, the image gets dark. I never noticed this issue since I was doing testing with other brands. But, recently, I just stared testing with Samsung Galaxy and I found out that issue.
After several days doing research I found that one way to temporally solve it could be clearing the camera cache. Effectively, that works if you do it through the device camera setting, but I need to do it now by code, since I would like to trigger that event before the user uses the camera flash.
How can I accomplish that programmatically ?

Related

How to Capture a Picture without Previewing in Android Studio 2019

How to Capture a Picture without Previewing in Android Studio use camera2 api
Google is protecting their users from this feature. You are no longer going to be able to do this as of Android Pie (API 28). This was first reported as of February of 2018.
"According to a source code commit spotted by XDA Developers, Android P will detect and prevent background applications from accessing the camera."
https://www.androidauthority.com/android-p-camera-restrictions-839076/
https://www.xda-developers.com/android-p-background-apps-camera/
Since this is going to limit your ability to upgrade this feature, as well as possibly getting your app disabled in the Play store, I'd avoid doing this.
You don't have to Display the previews but you need to go through at least 5-6 previews before the image is even decent. You run into a lot of issues where the image is too dark because it hasn't taken in enough light or it is out of focus. So you would need to cycle through many images in the preview. You don't need to display them. Only then can you take an actual picture using the STILL_CAPTURE template.

Autofocus in Samsung S8+

A wrote an application using a camera (Camera2) some time ago. And it worked with Samsung S5 (Android 6). But with S8+ (Android 8) camera doesn't focus anymore. It's going from CONTROL_AF_STATE_INACTIVE to CONTROL_AF_STATE_ACTIVE_SCAN to CONTROL_AF_STATE_FOCUSED_LOCKED (and then cycles through last two states) but the camera doesn't focus.
But when for the first time I postpone autofocus start (for example for 1 - 2 seconds after opening camera device) camera focuses - but only this time. And then it backs to cycling through these states without focusing.
The only thing that helps is reopening camera device but it's unacceptable because of delay.
I was trying to use CONTROL_AF_MODE_CONTINUOUS_PICTURE instead of CONTROL_AF_MODE_MACRO and this works for S8 but doesn't work for S5 :/
Does anybody have an issue like this? I'll try to prepare SSCE but maybe somebody knows what to do?
this is a know glitch ...the Samsung forums have a possible solution:
https://us.community.samsung.com/t5/Galaxy-S8-Questions-and-Answers/Camera-Not-Focusing-and-Blurry-Photos/td-p/103058 - which appears to be a manufacturing / mechanical issue.
tapping the back might loosen the stuck lens (eg. while it switches the modes back and forth). I'd still check for the occasion, that it may still behave alike that when running on some other S8+ device. it's not exactly what one would expect from a brand-new smartphone, but there seems to be too little precision at the lens clearance. maybe try to RMA that device?

Camera stays blank on Oxygen4 (Android Nougat) with an OnePlus 3

I've the problem that some users with an Oneplus3 and the most recent Oxygen 4 version (Android Nougat) don't see any camera preview image anymore (it stays blank/black). The UI elements are still visible.
They also said in previous versions of oxygen OS the app was working correctly. I found out, that other apps got the same behaviour and fixed it, recently (i.e. Google's Cardboard Camera). But I don't know how to fix it and don't have a test device like the OP3.
I'm using the min SDK version 14 and the Camera API v1 with a SurfaceView to show the camera preview. On my phone (LG G4 with Marshmallow) the app works as expected.
Is somebody of you familiar with that issue and know how to fix it? What else can I try to solve that problem? Can you reproduce that issue on others phones with Android N, too?
You can find the source here: https://github.com/kloener/visor-android
For testing you can directly download it from Google Play (https://play.google.com/store/apps/details?id=de.visorapp.visor) or on github-releases (https://github.com/kloener/visor-android/releases)
kind regards and thanks
They need to give camera permission from application settings. I know they accept it while setting up app. But for Nougat user need to give an extra permission.

Animations are laggy on KitKat but smooth on Lollipop and up

I'm animating the movement of multiple views like this (basically just using y positioning):
View.animate()
.setInterpolator(new FastOutSlowInInterpolator())
.y(requiredCalculatedPosition)
.setDuration(400);
But the snippet has visible lags in KitKat and below while running buttery smooth on Lollipop+. (Only tested on emulators till now, with graphics managed by my GPU).
Android literally sucks when it comes to animating multiple UI views simultaneously in pre Lollipop versions. I managed to make things smoother by adding little delays in my animations, but I was unable to get rid of total animation flicker when animating more than one view. Also another thing - it also depends on device, usually flickering would appear in cheap devices with weak GPU like Acer or Asus tablets or so due to their GPU limitations. Generally it will work well in most devices like older Samsung Galaxy S2, S3. Also emulators can't emulate GPU well - this is a thing I find always disappointing compared to iOS emulators.

libGDX Causing Multitouch Problems

I am working on a game with a virtual joystick in the bottom right corner of the screen and a "move" button in the bottom left. So you use the joystick to point the character in the right direction and press the "move" button to go forward in that direction. This was all working great until today and now when I press on the screen to go forward my joystick is being affected. I know it is not a coding problem because I haven't opened the file that handles touches for 8 days and it has been working fine. Also after I close my app and then use another app that is completely separate from libGDX the multitouch is having the same issue. So do you guys think this is a problem with libGDX, my device, or am I just not coding the multitouch correctly for libGDX? I am using a Stage and the controls are Actors on the Stage I should note that after I restart my phone, the other app that is not using libGDX works correctly. It is only after I open my libGDX based game. So frustrated with this that I am about to give up on libGDX. I am happy to post any code that is requested.
EDIT: Please see comments below. This seems to be a specific issue with the Galaxy Nexus and probably some other Samsung devices as well. This libGDX based app has had no issues on other devices such as original droid, and ASUS Transformer tablet.
Turns out this is not a libGDX problem at all... Nor was it a problem with any of my code. There seems to be a bug in the way the Galaxy Nexus handles multitouch. You can view the bug report at this link. Seems that as of 4.0.4 there still is no fix for this bug. I am still currently running a VZW Galaxy Nexus with 4.0.2, I guess all we can do is wait and put a disclaimer in our games until (if ever) it is fixed.
By locking and unlocking the device, the problem does go away (sometimes), but will quickly come back if I go to my homescreen and re-open the app.

Categories

Resources