title: Sending Accelerometer to C/C++
body: <p>I got the following code inside my templateApp.java:</p>
  
  <pre><code>    package com.android.templateApp;
  
      import android.app.Activity;
      import android.os.Bundle;
      import android.hardware.Sensor;
      import android.hardware.SensorEvent;
      import android.hardware.SensorEventListener;
      import android.hardware.SensorManager;
  
      public class templateApp extends Activity implements SensorEventListener
      {  
          GL2View mView;
  
          SensorManager mSensorManager;
  
          @Override protected void onCreate(Bundle icicle)
          {    
              super.onCreate( icicle );
  
              mSensorManager = ( SensorManager ) getSystemService( SENSOR_SERVICE );
  
              mView = new GL2View( getApplication() );
  
              mSensorManager.registerListener( this, 
                                               mSensorManager.getDefaultSensor( SensorManager.SENSOR_ACCELEROMETER ), 
                                               SensorManager.SENSOR_DELAY_GAME );
  
              setContentView( mView );
          }   
  
          @Override protected void onResume()
          {
              super.onResume();
  
              mView.onResume();
          }    
  
  
          public static native void Accelerometer( float x, float y, float z );
  
          public void onSensorChanged( SensorEvent event )
          {
              float x = event.values[ SensorManager.DATA_X ],
                    y = event.values[ SensorManager.DATA_Y ],
                    z = event.values[ SensorManager.DATA_Z ];
  
              // ALWAYS CRASH HERE!!!!
              Accelerometer( x, y, z );
          }
  
          public void onAccuracyChanged( Sensor sensor, int arg1 ) {}
      }
  </code></pre>
  
  <p>And inside my templateApp.cpp I got the following to bridge the Accelerometer function:</p>
  
  <pre><code>    extern "C"
      {
          JNIEXPORT void JNICALL Java_com_android_templateApp_GL2View_Init( JNIEnv *env, jobject obj,  jint width, jint height );
  
  
          JNIEXPORT void JNICALL Java_com_android_templateApp_templateApp_Accelerometer( JNIEnv *env, jfloat x, jfloat y, jfloat z );
      };
  
      JNIEXPORT void JNICALL Java_com_android_templateApp_GL2View_Init( JNIEnv *env, jobject obj,  jint width, jint height )
      { Init( width, height); }
  
      JNIEXPORT void JNICALL Java_com_android_templateApp_templateApp_Accelerometer( JNIEnv *env, jfloat x, jfloat y, jfloat z )
      { Accelerometer( x, y,z ); }
  </code></pre>
  
  <p>When I pass my mouse over in eclipse it show that the call belong to
  com.android.templateApp.templateApp.Accelerometer, which is exactly what I declare, however it always crash reporting an UnsatisfiedLinkError.</p>
  
  <p>I tried every combination (assuming that my native definition is wrong) but it keep crashing at the Accelerometer call inside the java code... Weird thing is that my init function that is inside my GL2View.java work flawless. Is there anything that prevent me to call a native API from the main file that extends Activity? Cuz the sensor work, I print the value its the native call that crash and I don't know why.</p>
  
  <p>Tks in advance!</p>