如何将jni中的参数传递给java.in我的情况下我想将getUniqueTargetId传递给java(android)。谢谢您的帮助 :) `class CloudImageTarget_UpdateCallback:public QCAR :: UpdateCallback {virtual void QCAR_onUpdate(QCAR :: State& state) {
QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
QCAR::ImageTracker* imageTracker = static_cast<QCAR::ImageTracker*>(
trackerManager.getTracker(QCAR::ImageTracker::getClassType()));
QCAR::TargetFinder* finder = imageTracker->getTargetFinder();
const int statusCode = finder->updateSearchResults();
if (statusCode < 0)
{
showErrorMessage(statusCode, state.getFrame().getTimeStamp());
}
else if (statusCode == QCAR::TargetFinder::UPDATE_RESULTS_AVAILABLE)
{
// Process new search results
if (finder->getResultCount() > 0)
{
const QCAR::TargetSearchResult* result = finder->getResult(0);
if (result->getTrackingRating() > 0)
{
QCAR::Trackable* newTrackable = finder->enableTracking(*result);
if (newTrackable != 0)
{
LOG("Successfully created new trackable '%s' with rating '%d'.",
newTrackable->getName(), result->getTrackingRating());
LOG( "Comparing Strings. currentTargetId: %s lastTargetId: %s",
result->getUniqueTargetId(), lastTargetId);
if (strcmp(result->getUniqueTargetId(), lastTargetId) != 0)
{
renderState = RS_LOADING;
snprintf(targetMetadata, CONTENT_MAX, "%s",result->getMetaData());
}
else
renderState = RS_NORMAL;
pthread_mutex_lock(&framesToSkipMutex);
framesToSkipBeforeRenderingTransition = 10;
pthread_mutex_unlock(&framesToSkipMutex);
// Initialize state variables
trackingStarted = false;
// Updates the value of the current Target Id with the new target found
pthread_mutex_lock(&lastTargetIdMutex);
strcpy(lastTargetId, result->getUniqueTargetId());
pthread_mutex_unlock(&lastTargetIdMutex);
enterContentMode();
}
else
LOG("Failed to create new trackable.");
}
}
}
}
}; `
答案 0 :(得分:0)
您可以使用反射调用JNI中的参数并将其传递给Java。
在Java类中创建一个方法
void setUniqueTargetID(int targetID) {
this.targetID = targetID;
}
在你的JNI中动态获取课程
jclass clazz = (*env)->FindClass(env, "complete_package_name/class_name");
获取方法
jmethodID setUniqID= (*env)->GetMethodID(env, clazz, "setUniqueTargetID", "(I)");
(*env)->CallObjectMethod(env, obj, setUniqID, ID);
答案 1 :(得分:0)
到目前为止我的代码:
// inside virtual void QCAR_onUpdate(QCAR :: State&amp; state)void我把这段代码:
jclass cls = env->FindClass("com/qualcomm/QCARSamples/CloudImageTarget/CloudImageTarget");
jmethodID mid = env->GetMethodID(cls,"getUniqeTargetID", "([Ljava/lang/String;)V");
env->CallObjectMethod(jObj, mid,newTrackable->getName());
in java i create method
String Msg;
public void getUniqeTargetID(String msg) {
this.Msg = msg;
}
\\in initApplicationAR i call the method:
Log.d(TAG,"Target_Name: "+ Msg);
log的结果:Target_Name:null ..
谢谢你的帮助Dayanand,请纠正我。谢谢你们。)