2

I would like to ask if there is a way to turn on/off the LED of the camera using the NDK code. I have done it using Java code but I need to do it faster so I think NDK code is what I am looking for. Is there another way?

I am trying to do it on a Galaxy Nexus but I cannot find the LED control file in order to set its brightness. Any help?

Thanks!

Mike Vasi
  • 467
  • 2
  • 5
  • 16

1 Answers1

3

Stick with your Java implementation. (No Google provided NDK API.)

Other Google Group Discussions asking the same question:

https://groups.google.com/forum/#!topic/android-ndk/EK3gPnu30Nw

https://groups.google.com/forum/#!msg/android-ndk/AyEMaRshntM/qlmnXptzfDMJ

Please read the "Performance Tips" about Android. Google specifically says do not use the NDK for "porting" and not "speeding up":

Native code is primarily useful when you have an existing native codebase that you want to port to Android, not for "speeding up" parts of your Android app written with the Java language.

Read the whole part on NDK performance tips here:

Use Native Methods Carefully

Developing your app with native code using the Android NDK isn't necessarily more efficient than programming with the Java language. For one thing, there's a cost associated with the Java-native transition, and the JIT can't optimize across these boundaries. If you're allocating native resources (memory on the native heap, file descriptors, or whatever), it can be significantly more difficult to arrange timely collection of these resources. You also need to compile your code for each architecture you wish to run on (rather than rely on it having a JIT). You may even have to compile multiple versions for what you consider the same architecture: native code compiled for the ARM processor in the G1 can't take full advantage of the ARM in the Nexus One, and code compiled for the ARM in the Nexus One won't run on the ARM in the G1.

Native code is primarily useful when you have an existing native codebase that you want to port to Android, not for "speeding up" parts of your Android app written with the Java language.

If you do need to use native code, you should read our JNI Tips.

Tip: Also see Josh Bloch's Effective Java, item 54.

Source: http://developer.android.com/training/articles/perf-tips.html#NativeMethods

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • I see your point but I would like to turn on/off the LED at lets say 500Hz which is not possible with the Java implementation due to the fact that the OS is not real-time. – Mike Vasi Mar 15 '15 at 17:22
  • @MikeVasi I understand, do not get my wrong, I will there were more APIs accessible via the NDK. To be honest, newer devices like the Nexus 6 do not really use the LEDs anymore. This is the closest answer to someone who has accessed the LED outside of an app: https://groups.google.com/forum/#!msg/android-ndk/AyEMaRshntM/qlmnXptzfDMJ but you need Root. – Jared Burrows Mar 15 '15 at 17:25
  • According to the last link you posted there has to be a /sys/class/leds folder which I cannot find. I am using Cyanogenmod 11. – Mike Vasi Mar 15 '15 at 17:42
  • Yes, look at those dates. They are trying to find a "hackish" way of doing it. There is no NDK way of doing it. There is no API for this. – Jared Burrows Mar 15 '15 at 17:43
  • Alright. So there is no alternative? Like accessing the kernel or the camera driver or so? I am not aware of the options that's why I insist. – Mike Vasi Mar 15 '15 at 17:45
  • I have not found anything like that. OpenCV provides access to the Camera I believe because I have used it for Google Glass: http://opencv.org/platforms/android.html. – Jared Burrows Mar 15 '15 at 17:46
  • Ok I will have a look at it. Thank you for your replies and time. – Mike Vasi Mar 15 '15 at 17:48
  • @MikeVasi No problem, I wish we could do more with NDK. But I believe Google is right, we should only write portable code for the NDK such as "games". – Jared Burrows Mar 15 '15 at 17:55