Log in or register to post comments

FrameMarkers question

June 22, 2011 - 9:28pm #1

When the ”Q“ is displayed, how to get the return value of java code?

Re: FrameMarkers question

June 23, 2011 - 5:03pm #2

Are you asking how to get information about the currently detected markers to Java? If so, the answer is using the JNI (Java Native Interface). Here's some code to get you started:


int lastMarkerId = -1;

Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkersRenderer_renderFrame(JNIEnv *env, jobject obj)
    for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
        const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
        assert(trackable->http://ar.qualcomm.at/node/2000032<const QCAR::Marker*>(trackable);
        if (marker->getMarkerId() != lastMarkerId) {
            jstring js = env->NewStringUTF(marker->getName());
            jclass javaClass = env->GetObjectClass(obj);
            jmethodID method = env->GetMethodID(javaClass, "foundMarker", "(Ljava/lang/String;I)V");
            env->CallObjectMethod(obj, method, js, marker->getMarkerId());
            lastMarkerId = marker->getMarkerId();


public void foundMarker(String markerName, int markerId)
    DebugLog.LOGI("found marker named " + markerName + " with id " + markerId);
    // Note: we're in the GL Thread at this point, if you want to do anything
    // to the Android UI you must use a Handler or something similar to call the
    // code on the UI Thread

There's more code available here, which shows how to use a Handler to pop up a message on the screen: https://ar.qualcomm.com/arforums/showthread.php?p=70&postcount=2

- Kim

Log in or register to post comments