Log in or register to post comments

changing the action after recognized the tracker

May 15, 2012 - 3:58am #1

I'm new here and i'm also new to android..
I'm using ImageTarget sample to edit in, I want to change the action after recognized the tracker to open browser in a certain url.. so I want to put this code:

String upc = "http://www.example.com";
    	Uri uri = Uri.parse(upc); 
    	Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
    	startActivity(intent);

but I don't know where I've to put this code?
any help??

changing the action after recognized the tracker

April 4, 2013 - 11:48am #17

Hi.. I am trying to achieve the same and I am able to open a web browser but when I come back to the app the tracker is not recognized..m i missing something..following is my rederfame function:

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv* env, jobject obj)
{
    //LOG("Java_com_qualcomm_QCARSamples_ImageTargets_GLRenderer_renderFrame");

    // Clear color and depth buffer 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();
    
    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();
       
#ifdef USE_OPENGL_ES_1_1
    // Set GL11 flags:
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);
        
#endif

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
	
	// Did we find any trackables this frame?
	for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
	{
	    // Get the trackable:
	    const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
	    // Compare this trackable's id to a globally stored id
	    // If this is a new trackable, find the displayMessage java method and
	    // call it with the trackable's name
	    if (trackable->getId() != lastTrackableId) 
	    {
	        jstring js = env->NewStringUTF(trackable->getName());
	        jclass javaClass = env->GetObjectClass(obj);
	        jmethodID method = env->GetMethodID(javaClass, "displayMessage", "(Ljava/lang/String;)V");
	        env->CallVoidMethod(obj, method, js);
	        lastTrackableId = trackable->getId();
            }
    }
    glDisable(GL_DEPTH_TEST);

    #ifdef USE_OPENGL_ES_1_1        
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    #else
    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(textureCoordHandle);
    #endif

    QCAR::Renderer::getInstance().end();
 }

 

changing the action after recognized the tracker

July 23, 2012 - 12:59pm #16

Hello,

Please see my reply to your other post about putting text on a 3D plane, https://ar.qualcomm.at/content/how-change-teapot-text-vuforia-native . My code in this post will show a toast when a target is detected, i.e. 2D text on the screen not tracking to target. Just remove the code to open the URI in order to stop the web browser from opening.

Thank you,

-Peter

changing the action after recognized the tracker

July 19, 2012 - 8:20pm #15

how i can change the uri parse to info text.not launch a browser.....?can i change using u code peter?

changing the action after recognized the tracker

July 8, 2012 - 1:01am #14

thx

Re: changing the action after recognized the tracker

June 17, 2012 - 4:59am #13

what about the code to tap an object then show a toast??

Re: changing the action after recognized the tracker

June 15, 2012 - 10:50am #12

Hello davina,

My code is only to replace a portion of the code in ImageTargets.cpp. Those errors look like you may have replaced all the code with my code.

You need to leave most of the ImageTargets.cpp file in tact and only replace the relevant parts with my code.

Thank you,

-Peter

Re: changing the action after recognized the tracker

June 12, 2012 - 7:37am #11

I want to show transparent activity over android camera, after detecting marker, i send the message to android activity, here below my code is attached, any help would be helpful a lot. Thanks

int lastTrackableId = -1;

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkersRenderer_renderFrame(JNIEnv * env, jobject obj)
{
    //LOG("Java_com_qualcomm_QCARSamples_FrameMarkers_GLRenderer_renderFrame");
 
    // Clear color and depth buffer 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Get the state from QCAR and mark the beginning of a rendering section
    QCAR::State state = QCAR::Renderer::getInstance().begin();

    // Explicitly render the Video Background
    QCAR::Renderer::getInstance().drawVideoBackground();
    
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    // Did we find any trackables this frame?
  for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
    {
        // Get the trackable:
        const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
        
        // Compare this trackable's id to a globally stored id
        // If this is a new trackable, find the displayMessage java method and
        // call it with the trackable's name
        if (trackable->getId() != lastTrackableId) {
            jstring js = env->NewStringUTF(trackable->getName());
            jclass javaClass = env->GetObjectClass(obj);
            jmethodID method = env->GetMethodID(javaClass, "displayMessage", "(Ljava/lang/String;)V");
            env->CallVoidMethod(obj, method, js);
            lastTrackableId = trackable->getId();
        }
                QCAR::Renderer::getInstance().end();

    }

   

    QCAR::Renderer::getInstance().end();
}

Re: changing the action after recognized the tracker

May 29, 2012 - 6:16pm #10
mohamedepic wrote:

Hello Peter,
first i'm sorry for being late in this reply but I had some personal issues which delayed me...

second thanks a lot for your help it works great for me but i faced a new issue i need your help in, which is: when the camera detect the tracker the video works but if i go back and try to detect it again nothing happen. but if i detected another tracker image it works...
conclusion: i can't detect the same image tracker twice in row...

thanks

Hi

I had this same issue.

to pass trought it, i wrote a simple Method JNI on cpp that restarts "lastTrackableId" to -1

Easy and tell me how did you go

Re: changing the action after recognized the tracker

May 29, 2012 - 11:42am #9

Hello mohamedepic,

Try removing references and checks for lastTrackableID in ImageTargets.cpp to prevent this from happening. I am using this check in the sample to prevent the toast from always displaying on screen.

Thank you,

-Peter

Re: changing the action after recognized the tracker

May 28, 2012 - 7:02am #8

Hello Peter,
first i'm sorry for being late in this reply but I had some personal issues which delayed me...

second thanks a lot for your help it works great for me but i faced a new issue i need your help in, which is: when the camera detect the tracker the video works but if i go back and try to detect it again nothing happen. but if i detected another tracker image it works...
conclusion: i can't detect the same image tracker twice in row...

thanks

Re: changing the action after recognized the tracker

May 16, 2012 - 9:59am #7

Hi mohamedepic,

Make sure to run ndk-build after editing the ImageTargets.cpp file. Also clean your project in Eclipse to make sure the new shared library is loaded after rebuilding.

Thank you,

-Peter

Re: changing the action after recognized the tracker

May 16, 2012 - 6:47am #6

and if I update the ImageTarget.java like this:

/** Called when the activity will start interacting with the user.*/
    protected void onResume()
    {
    	ImageTargetsRenderer.mainActivityHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
            	String text = (String) msg.obj;
            	// The Toast display the name of the detected trackable on the screen
            	Context context = getApplicationContext();
            	int duration = Toast.LENGTH_SHORT;
            	Toast toast = Toast.makeText(context, text, duration);
            	toast.show();
            	
            	// The following opens a pre-defined URL based on the name of trackable detected
            	if (text.equalsIgnoreCase("stones")) {
            		Uri uriUrl = Uri.parse("http://ar.qualcomm.at");
                	Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl); 
                	startActivity(launchBrowser);
            	}
            	if (text.equalsIgnoreCase("chips")) {
            		Uri uriUrl = Uri.parse("http://developer.qualcomm.com");
                	Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl); 
                	startActivity(launchBrowser);
            	}
            }
        };
  }
   

the app crashes...
more help please..

Re: changing the action after recognized the tracker

May 16, 2012 - 4:50am #5

Thanks Peter for your reply..
I've just tried your suggestion but it still show the kettle and don't launch the browser as we want?

any suggestion?

Re: changing the action after recognized the tracker

May 15, 2012 - 11:04am #4

Hello mohamedepic,

Here are the step to do this and also display a Toast of which trackable is found:

1. Update ImageTargets.cpp as follows

int lastTrackableId = -1;

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv* env, jobject obj)
{
    ...
    
    // Did we find any trackables this frame?
    for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
    {
        // Get the trackable:
        const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
        
        // Compare this trackable's id to a globally stored id
        // If this is a new trackable, find the displayMessage java method and
        // call it with the trackable's name
        if (trackable->getId() != lastTrackableId) {
            jstring js = env->NewStringUTF(trackable->getName());
            jclass javaClass = env->GetObjectClass(obj);
            jmethodID method = env->GetMethodID(javaClass, "displayMessage", "(Ljava/lang/String;)V");
            env->CallVoidMethod(obj, method, js);
            lastTrackableId = trackable->getId();
        }
                QCAR::Renderer::getInstance().end();

    }

2. Update ImageTargetsRenderer.java as follows

	    public void displayMessage(String text)
	    {
	        // We use a handler because this thread cannot change the UI
	    	Message message = new Message();
	    	message.obj = text;
	        mainActivityHandler.sendMessage(message);
	    }

3. Add the Handler to resolve the error in ImageTargetsrenderer.java. At the beginning of the class definition add.

public static Handler mainActivityHandler;

4. Add the Handler to ImageTargets.java in the onResume() Method

	        ImageTargetsRenderer.mainActivityHandler = new Handler() {
	            @Override
	            public void handleMessage(Message msg) {
	            	String text = (String) msg.obj;
	            	// The Toast display the name of the detected trackable on the screen
	            	Context context = getApplicationContext();
	            	int duration = Toast.LENGTH_SHORT;
	            	Toast toast = Toast.makeText(context, text, duration);
	            	toast.show();
	            	
	            	// The following opens a pre-defined URL based on the name of trackable detected
	            	if (text.equalsIgnoreCase("stones")) {
	            		Uri uriUrl = Uri.parse("http://ar.qualcomm.at");
	                	Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl); 
	                	startActivity(launchBrowser);
	            	}
	            	if (text.equalsIgnoreCase("chips")) {
	            		Uri uriUrl = Uri.parse("http://developer.qualcomm.com");
	                	Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl); 
	                	startActivity(launchBrowser);
	            	}
	            }
	        };

Thank you,

-Peter

Log in or register to post comments