user1244932
user1244932

Reputation: 8082

Android: proper use of ndk for newbie?

  1. According to this there are a lot of sensors types that available via NDK, but not GPS? Am I right and GPS accessible only via JNI?

  2. Is it possible to process sensor events in background with active Java Activity? I want to handle accelerometer and gyroscope events in native code and two times per second show it in window (java activity). But if I have NativeActivity to handle sensor events, it should be on foreground, so I can not show result of processing without stopping processing, if I use java activity to show result?

  3. How handle bitmaps? I have native library to create bitmap with map, then I want to draw a lot of objects over this bitmap with lot of calls for geographical coordinates<->screen coordinates. At first I thought to implement this on native side and use Java only to draw bitmap in Activity, but looks like NDK have no 2D drawing stuff, only to get bitmap from java, and put it back to java.

Upvotes: 0

Views: 112

Answers (1)

Sergio
Sergio

Reputation: 8209

  1. NDK gives access to the same set of sensors as Java framework does. And yes, there is no GPS, moreover it is not a sensor in common sense.

  2. Sensor event handling doesn't depend on Activity lifecycle, so you can just create dedicated ASensorEventQueue and obtain results via your ALooper_callbackFunc.

  3. NDK gives only ability to test Bitmap's size, pixel format and to get access to pixel buffer which you can freely modify. (The last one is for mutable bitmaps only). There is no 2D drawing API. You should use third-party software for such purpose. Bytheway you can try OpenGL for your drawing. It requires no Bitmap and only ANativeWindow.

Upvotes: 1

Related Questions