Mike Vasi
Mike Vasi

Reputation: 477

Turn on/off camera LED using NDK code Android

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!

Upvotes: 2

Views: 1240

Answers (1)

Jared Burrows
Jared Burrows

Reputation: 55517

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

Upvotes: 3

Related Questions