We recently had an accident with one of our Galaxy S10 units in the office, where the rear camera would suddenly refuse to focus. This made me think back on how many times I've encountered this problem over the years, on different devices. And since the same thing that I've been doing to fix the issue in the past worked like a charm on the Galaxy S10, we thought we'd write a few tips that may help you resolve the problem on your device.
If you've done some research on the issue already, then you've probably stumbled upon many tips involving restarting your device, force-closing the camera app, clearing the cache, and others. However, since this issue is more likely than not related to the hardware inside your device, we're going to skip those for now. Of course, feel free to go through all basic troubleshooting steps just to make sure.
Cameras are able to focus by changing the distance between the lens and the sensor. Your phone has a set of tiny lenses that move back and forth, thus changing where the captured light converges on the sensor, which determines what is in focus and what isn't. Don't think too hard about it. All you need to know, is that there's tiny stuff moving in your phone and things sometimes get stuck.
Once you've gone through all the basic troubleshooting steps, such as force-closing the camera app and restarting your device, there's something else you might want to try out. If your phone has a manual camera mode, enable it and look for the manual focus setting. Now try moving the slider left and right to see whether this changes the focus. More likely than not, it won't, but it's still worth a try.
Alright, now that you've tried everything else, time for the simplest fix, which also has the highest success rate, in our experience. Turn your phone around and give the camera a firm tap with your finger. Seriously, just tap the camera. In most cases, this should help the camera snap back into focus. If it doesn't, try shaking the phone or firmly tapping it against your palm. It may sound counter-intuitive to whack your expensive new phone around like its some old CRT TV, but it does genuinely work.
The causes for camera focusing issues can be numerous and varied. As we already said, it could just be a one-time occurrence, because there's tiny things moving around and sometimes, they get stuck. However, the issue could also be a result of physical or liquid damage inside the device. If you've recently dropped or soaked your phone (depending on its IP rating), you may want to keep an eye out for recurring issues.
If you haven't mishandled your device in any way, this could just be a random issue that goes away. However, if it happens again, we would advise you to take advantage of your warranty and consult an expert.