# Camera extension for Android?

**URL:** <https://forum.defold.com/t/camera-extension-for-android/15670>\
**Category:** Questions\
**Created:** [December 26, 2017, 2:16pm UTC](https://forum.defold.com/t/camera-extension-for-android/15670 "2017-12-26T14:16:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![geidnert](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/geidnert/32/26706_2.png) [@geidnert](https://forum.defold.com/u/geidnert)\
**Post date:** [December 26, 2017, 2:16pm UTC](https://forum.defold.com/t/camera-extension-for-android/15670/1 "2017-12-26T14:16:19Z")

</div>

How do i depend on other versions than the master, would like to do it on the camera extensions for example so i can build a Android version as well, does that one only work for Android or Both? @britzl

---

<div class="post-metadata">

**Author:** ![geidnert](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/geidnert/32/26706_2.png) [@geidnert](https://forum.defold.com/u/geidnert)\
**Post date:** [December 26, 2017, 9:30pm UTC](https://forum.defold.com/t/camera-extension-for-android/15670/2 "2017-12-26T21:30:45Z")

</div>

yes, i got it now, but what do i have to do in my app to make it work on a Android build? it did not work just to build a new android target and install it on the phone, the camera did not start on the phone? @britzel

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [December 26, 2017, 10:05pm UTC](https://forum.defold.com/t/camera-extension-for-android/15670/3 "2017-12-26T22:05:19Z")

</div>

We do not really have any decent Android support for the camera yet. I was hoping to have time to add proper native support on Android ([Android support · Issue #2 · defold/extension-camera · GitHub](https://github.com/defold/extension-camera/issues/2)). The branch containing Android camera support results in slow capture of camera frames on Android. If you want to try the Android branch all you have to do is select the branch on GitHub and then get the link to the zip. Like this:

 ![58](https://forum-defold-uploads.b-cdn.net/original/2X/3/3a4965aca446f10eaf27058f1cff3cbb20cafe84.png)

---

<div class="post-metadata">

**Author:** ![geidnert](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/geidnert/32/26706_2.png) [@geidnert](https://forum.defold.com/u/geidnert)\
**Post date:** [December 26, 2017, 10:09pm UTC](https://forum.defold.com/t/camera-extension-for-android/15670/4 "2017-12-26T22:09:10Z")

</div>

I have done that all ready, but it doesn’t work with the same LUA app code that works for IOS, on the android phone, the camera never starts.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [December 27, 2017, 7:55am UTC](https://forum.defold.com/t/camera-extension-for-android/15670/5 "2017-12-27T07:55:10Z")

</div>

Oh, ok, well it’s experimental and I thought I did leave it in a working state. I’m not able to look into it now (traveling).

---

<div class="post-metadata">

**Author:** ![geidnert](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/geidnert/32/26706_2.png) [@geidnert](https://forum.defold.com/u/geidnert)\
**Post date:** [December 27, 2017, 6:50pm UTC](https://forum.defold.com/t/camera-extension-for-android/15670/6 "2017-12-27T18:50:31Z")

</div>

I understand, no worries! whenever you got some time again! 🙂 maybe i need to do something with the ext.manifest file included in the camera extension?

---

<div class="post-metadata">

**Author:** ![geidnert](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/geidnert/32/26706_2.png) [@geidnert](https://forum.defold.com/u/geidnert)\
**Post date:** [January 12, 2018, 6:55am UTC](https://forum.defold.com/t/camera-extension-for-android/15670/7 "2018-01-12T06:55:58Z")

</div>

Anyone have some time to look at this or give a hint on whats needed to get the camera extension to work on Android as well?anyone else than @britzl, he probably have better things to do 🙂

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 12, 2018, 7:43am UTC](https://forum.defold.com/t/camera-extension-for-android/15670/8 "2018-01-12T07:43:40Z")

</div>

I tried the dev-android branch and it worked on Android (although it’s slow and it looked like the colours were slightly blueish). What happens when you’re testing it? Does it crash? Note that you need to use this URL as a dependency:

[https://github.com/defold/extension-camera/archive/dev-android.zip](https://github.com/defold/extension-camera/archive/dev-android.zip)

---

<div class="post-metadata">

**Author:** ![geidnert](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/geidnert/32/26706_2.png) [@geidnert](https://forum.defold.com/u/geidnert)\
**Post date:** [January 12, 2018, 8:52am UTC](https://forum.defold.com/t/camera-extension-for-android/15670/9 "2018-01-12T08:52:12Z")

</div>

I do have that URL as dependency, Do i need to do something more than that? can i use the same LUA code i have that works for IOS? do i need to point out the manifest file or something?

When i click the “take photo” buton in my app, on IOS the camera starts and i can take a photo, but when i click the same button on Android, the camera does not start, i get no crash, nothing happens.

Dont i need to give permissions on the phone for using the camera like i do on IOS? i never get a question for that on Android?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 12, 2018, 10:23am UTC](https://forum.defold.com/t/camera-extension-for-android/15670/10 "2018-01-12T10:23:03Z")

</div>

> [@geidnert](#):
>
> can i use the same LUA code i have that works for IOS?

Yes, same Lua code. That’s the point with the native extensions that the Lua API should be the same and the underlying native code will abstract away the differences.

> [@geidnert](#):
>
> Dont i need to give permissions on the phone for using the camera like i do on IOS? i never get a question for that on Android?

Yes you need that on Android as well. There’s an AndroidManifest.xml file in the root of the project, used by the example app.

> <https://github.com/defold/extension-camera/blob/dev-android/AndroidManifest.xml#L128>

---

<div class="post-metadata">

**Author:** ![geidnert](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/geidnert/32/26706_2.png) [@geidnert](https://forum.defold.com/u/geidnert)\
**Post date:** [January 12, 2018, 11:46am UTC](https://forum.defold.com/t/camera-extension-for-android/15670/11 "2018-01-12T11:46:20Z")

</div>

Yes, that manifest file made it work, but like you said, its very blue and slow, and the image is rotated 45 degrees. But at least i get an image!! Yay!! 🙂

I guess its not even on the horizon to continue on this extension and make it just a little bit better, is it?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 12, 2018, 1:08pm UTC](https://forum.defold.com/t/camera-extension-for-android/15670/12 "2018-01-12T13:08:07Z")

</div>

> [@geidnert](#):
>
> on the horizon to continue on this extension and make it just a little bit better, is it?

It’s on the horizon, but for me far away. Why not go ahead and try it yourself? [There’s an issue with a link](https://github.com/defold/extension-camera/issues/2) to an NDK camera implementation that if used should be significantly faster than the current Android version.

---

<div class="post-metadata">

**Author:** ![jouni.petteri.pekone](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@jouni.petteri.pekone](https://forum.defold.com/u/jouni.petteri.pekone)\
**Post date:** [January 18, 2018, 11:09am UTC](https://forum.defold.com/t/camera-extension-for-android/15670/13 "2018-01-18T11:09:35Z")

</div>

To make it run faster remove following lines in camera.java function onPreviewFrame  
surfaceView.setVisibility(View.VISIBLE);  
camera.startPreview();  
surfaceView.setVisibility(View.INVISIBLE);

To fix color in camera\_android.cpp functions yuv to rgb transfomation switch Cb and Cr around.  
I also had to change in same function direction of j get image in correct way.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 18, 2018, 11:51am UTC](https://forum.defold.com/t/camera-extension-for-android/15670/14 "2018-01-18T11:51:20Z")

</div>

> [@jouni.petteri.pekone](#):
>
> remove following lines in camera.java function onPreviewFrame

Won’t that result in a fullscreen camera? The idea is to not use the camera preview and then only grab frames and display those somehow (as a texture on a quad for instance).

> [@jouni.petteri.pekone](#):
>
> To fix color in camera\_android.cpp functions yuv to rgb transfomation switch Cb and Cr around.
> 
> I also had to change in same function direction of j get image in correct way.

Would you mind submitting a PR?

---

<div class="post-metadata">

**Author:** ![jouni.petteri.pekone](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@jouni.petteri.pekone](https://forum.defold.com/u/jouni.petteri.pekone)\
**Post date:** [January 18, 2018, 1:00pm UTC](https://forum.defold.com/t/camera-extension-for-android/15670/15 "2018-01-18T13:00:14Z")

</div>

> [@britzl](#):
>
> Won’t that result in a fullscreen camera? The idea is to not use the camera preview and then only grab frames and display those somehow (as a texture on a quad for instance).

I can’t think of any other use than grap preview frames and show them on sprite/quad.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 18, 2018, 6:35pm UTC](https://forum.defold.com/t/camera-extension-for-android/15670/16 "2018-01-18T18:35:55Z")

</div>

Exactly. But are you saying that it works when those three lines are removed? Have you tried on different Android versions?

---

<div class="post-metadata">

**Author:** ![jouni.petteri.pekone](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/j/eb9ed0/32.png) [@jouni.petteri.pekone](https://forum.defold.com/u/jouni.petteri.pekone)\
**Post date:** [January 19, 2018, 8:31am UTC](https://forum.defold.com/t/camera-extension-for-android/15670/17 "2018-01-19T08:31:06Z")

</div>

I have tried on Samsung galaxy j1 (android 4.4.4) and Sony xperia something (android 7.0). On J1 those lines actually caused some flickering.  
I assume that startCapture function’s surfaceCreated sets surfaceView invisible and that it stays like that.

---

<div class="post-metadata">

**Author:** ![geidnert](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/geidnert/32/26706_2.png) [@geidnert](https://forum.defold.com/u/geidnert)\
**Post date:** [January 22, 2018, 12:02pm UTC](https://forum.defold.com/t/camera-extension-for-android/15670/18 "2018-01-22T12:02:29Z")

</div>

This is interesting, something is happening after all! 🙂

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 24, 2018, 11:35am UTC](https://forum.defold.com/t/camera-extension-for-android/15670/19 "2018-01-24T11:35:42Z")

</div>

> [@jouni.petteri.pekone](#):
>
> To make it run faster remove following lines in camera.java function onPreviewFrame
> 
> surfaceView.setVisibility(View.VISIBLE);  
> camera.startPreview();  
> surfaceView.setVisibility(View.INVISIBLE);

This does not work on my HTC One M9 (Android 7). I get a single frame and nothing more.

---

<div class="post-metadata">

**Author:** ![geidnert](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/geidnert/32/26706_2.png) [@geidnert](https://forum.defold.com/u/geidnert)\
**Post date:** [March 9, 2018, 6:51am UTC](https://forum.defold.com/t/camera-extension-for-android/15670/20 "2018-03-09T06:51:51Z")

</div>

@britzl any news on this.. still no time for you to look at it i guess?

[Next page](https://forum.defold.com/t/camera-extension-for-android/15670.md?page=2)
