简体   繁体   中英

Android studio C++ ndk camera

I created C/C++ project in android studio and I want to use NDK camera. I wrote in my cpp file

#include <camera/NdkCameraMetadata.h>
#include <camera/NdkCameraManager.h>
#include <camera/NdkCameraDevice.h>
#include <jni.h>
#include <string>


extern "C" JNIEXPORT jstring JNICALL
Java_com_example_test_MainActivity_listDevices(JNIEnv* env, jobject)
{
   std::string text;

   ACameraIdList *camList;
   ACameraManager *camManager;

   camManager = ACameraManager_create();

   camera_status_t result = ACameraManager_getCameraIdList(camManager, &camList);

   if (result == ACAMERA_OK)
   {
       text = "Error List devices";
   }
   else
   {
       text = "Device listed";
   }

   return env->NewStringUTF(text.c_str());;
}

but Android studio is writing

"Can't resolve type ACameraIdList"

What I'm doing wrong? I just added this code into .cpp file, nothing else. Idid not changed any other files.

As mentioned in the comments, you need to set the minSDK to 24 or higher.

The NdkCameraDevice.h header files detects the minSDK using the __ANDROID_API__ identifier:

#if __ANDROID_API__ >= 24
      ...
typedef struct ACameraIdList {
    int numCameras;          ///< Number of camera device Ids
    const char** cameraIds;  ///< list of camera device Ids
} ACameraIdList;
      ...
#endif

This means that if the minSDK is below 24 the C preprocessor will omit the declaration of ACameraIdList and other related structures and functions. This leads to the "Can't resolve type ACameraIdList" error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM