# Auto Focus using Android Camera Plugin - is it possible?

**URL:** <https://forums.unrealengine.com/t/auto-focus-using-android-camera-plugin-is-it-possible/125903>\
**Category:** Mobile\
**Tags:** unreal-engine, Android\
**Created:** [May 8, 2019, 2:12pm UTC](https://forums.unrealengine.com/t/auto-focus-using-android-camera-plugin-is-it-possible/125903 "2019-05-08T14:12:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SeanJD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SeanJD](https://forums.unrealengine.com/u/SeanJD)\
**Post date:** [May 8, 2019, 2:12pm UTC](https://forums.unrealengine.com/t/auto-focus-using-android-camera-plugin-is-it-possible/125903/1 "2019-05-08T14:12:37Z")

</div>

The title says it all really.

I’m using the built-in Android Camera Player plugin (version 2.0 , UE 4.21) and can stream the backfacing camera through to a Media Texture and display it at runtime but it’s kind of pointless as it’s out of focus.  
Does anyone know how to enable android’s android.hardware.camera.autofocus feature via this plugin? Or any other way?

I found an old plugin [here](https://forums.unrealengine.com/development-discussion/engine-source-github/89840-plugin-android-camera/page5) which mentions being able to edit an xml file in the plugin to enable it but that’s a 3rd party plugin and it won’tr compile for recent versions of the engine.

Any ideas?

I could use the ARCore plugin but it’s not compatible on the device/s I need it for.

Thanks

---

<div class="post-metadata">

**Author:** ![RobMilliken](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RobMilliken](https://forums.unrealengine.com/u/RobMilliken)\
**Post date:** [April 3, 2020, 4:13am UTC](https://forums.unrealengine.com/t/auto-focus-using-android-camera-plugin-is-it-possible/125903/2 "2020-04-03T04:13:02Z")

</div>

That old plugin you mention. Should still work for recent versions of the engine. Can I ask the difficulties that you are having?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_15185e6e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_15185e6e](https://forums.unrealengine.com/u/anonymous_user_15185e6e)\
**Post date:** [May 18, 2020, 6:08am UTC](https://forums.unrealengine.com/t/auto-focus-using-android-camera-plugin-is-it-possible/125903/3 "2020-05-18T06:08:47Z")

</div>

Well maybe it is late but it can help other people who face same problem. I’ve solved android camera focus problem. There is CameraPlayer14.java file at this folder “C:\Program Files\Epic Games\UE\_X.XX\Engine\Plugins\Media\AndroidCamera\Source\AndroidCamera\Java\src\com\epicgames\ue4”. You should add line “param.setFocusMode(“continuous-picture”);” after line 520. And this should add auto focus. I think this must be added to official plugin.

---

<div class="post-metadata">

**Author:** ![hexitex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@hexitex](https://forums.unrealengine.com/u/hexitex)\
**Post date:** [May 24, 2020, 7:05pm UTC](https://forums.unrealengine.com/t/auto-focus-using-android-camera-plugin-is-it-possible/125903/4 "2020-05-24T19:05:49Z")

</div>

Thanks vristok, what is the the compile procedure?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_15185e6e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_15185e6e](https://forums.unrealengine.com/u/anonymous_user_15185e6e)\
**Post date:** [May 27, 2020, 8:31am UTC](https://forums.unrealengine.com/t/auto-focus-using-android-camera-plugin-is-it-possible/125903/5 "2020-05-27T08:31:26Z")

</div>

It compiles during android packaging. Also I had a problem with low FPS. I solved it changing the same CameraPlayer14.java file at lines 516 and 517. I changed these lines on:  
width = previewSizes.get(0).width;  
height = previewSizes.get(0).height;

P.S.  
You have to consider that you should make this changes every time you install new engine version, so it is a good idea to save changed file anywhere.

---

<div class="post-metadata">

**Author:** ![eray\_ozr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eray\_ozr](https://forums.unrealengine.com/u/eray_ozr)\
**Post date:** [January 3, 2023, 2:59am UTC](https://forums.unrealengine.com/t/auto-focus-using-android-camera-plugin-is-it-possible/125903/6 "2023-01-03T02:59:29Z")

</div>

UE5.1 packages but android app crashes on Galaxy S21 when I chose back camera.  
Also I tried this after yours.  
param.setFocusMode(Camera.Parameters.FOCUS\_MODE\_CONTINUOUS\_PICTURE);

edit:  
Tried this (and alose with else if)

```auto
		List<String> focusModes = param.getSupportedFocusModes();
		if (focusModes.contains(param.FOCUS_MODE_CONTINUOUS_VIDEO)) 
		{
			param.setFocusMode(param.FOCUS_MODE_CONTINUOUS_VIDEO);
		}

		if (focusModes.contains(param.FOCUS_MODE_CONTINUOUS_PICTURE))
		{
			param.setFocusMode(param.FOCUS_MODE_CONTINUOUS_PICTURE);
		}

		if (focusModes.contains(param.FOCUS_MODE_FIXED))
		{
			param.setFocusMode(param.FOCUS_MODE_FIXED);
		}

		if (focusModes.contains(param.FOCUS_MODE_INFINITY))
		{
			param.setFocusMode(param.FOCUS_MODE_INFINITY);
		}

```

I don’t get any crash but also there is no visible focus.
