title: Implement Native Function Android APP and C
body: <p>I need to implement native function in Android app.</p>
  
  <p>Function:</p>
  
  <pre><code>public native int RFIDPower (String path, String data);   
  
  public void RFIDPowerEnable(boolean isEnable){   
  String path = "/dev/RFID_enable"; 
  if (isEnable)    
  RFIDPower(path, “1”);
  else
  RFIDPower(path, “0”);
   }
  </code></pre>
  
  <p>AND THIS IS THE C code:</p>
  
  <pre><code>JNIEXPORT jint JNICALL Java_com_winmate_demo_main_RFIDPower (JNIEnv * env, jobject thiz, jstring path, jstring data)
  {   
  int fd = 0;
  const char *cPath, *cData;
  if (path == NULL) return -1;
  // Convert jstring to char pointer
  cPath = (*env)-&gt;GetStringUTFChars(env, path, NULL);
  cData = (*env)-&gt;GetStringUTFChars(env, data, NULL); 
  // Open node “/dev/RFID_enable”   
  fd = open(cPath, O_WRONLY | O_NOCTTY | O_NDELAY | O_NONBLOCK);
  if (fd &lt; 0) {
  (*env)-&gt;ReleaseStringUTFChars(env, path, cPath); 
  (*env)-&gt;ReleaseStringUTFChars(env, data, cData);
  return -1;
  }
  write(fd, cData, strlen(cData));
  (*env)-&gt;ReleaseStringUTFChars(env, path, cPath);
  (*env)-&gt;ReleaseStringUTFChars(env, data, cData);
  close(fd);  
  return 0;
  } 
  </code></pre>