Log in or register to post comments

Button for changing Device Database to Cloud Database imagetargets sample

October 29, 2013 - 4:37am #1

Hello.. I'm new to both Android and Vuforia: 

I want to create a button for switching device database and cloud database. 

The application works, it switches between device and cloud when I press the button, but the background of the UI suddenly turns black and sometimes green, then the application restarted. What have I done wrong? Thank you very much for your help..

Here is the code for switching database button:

else if (item == itemSwitchDatasetIndex)
{
   switchDatabase();
   // Cancel potentially running tasks
   if (mInitQCARTask != null &&
   mInitQCARTask.getStatus() != InitQCARTask.Status.FINISHED)
   {
       mInitQCARTask.cancel(true);
       mInitQCARTask = null;
   }

   if (mLoadTrackerTask != null &&
   mLoadTrackerTask.getStatus() != LoadTrackerTask.Status.FINISHED)
   {
       mLoadTrackerTask.cancel(true);
       mLoadTrackerTask = null;
   }
   // Deinit code for Cloud Reco service
   if (mInitCloudRecoTask != null
   && mInitCloudRecoTask.getStatus() != InitCloudRecoTask.Status.FINISHED)
   {
       mInitCloudRecoTask.cancel(true);
       mInitCloudRecoTask = null;
   }

   // Ensure that all asynchronous operations to initialize QCAR
   // and loading the tracker datasets do not overlap:
   synchronized (mShutdownLock) 
   {

       // Do application deinitialization in native code:
       deinitApplicationNative();

       // Unload texture:
       //mTextures.clear();
       //mTextures = null;

       // Destroy the tracking data set:
       destroyTrackerData();

       // Deinit the tracker:
       deinitTracker();

       // Deinitialize QCAR SDK:
       QCAR.deinit();
                                
       // Deinit Cloud Reco
       deinitCloudReco();
   }
   System.gc();
   databaseDevice=!databaseDevice;
   updateApplicationStatus(APPSTATUS_INIT_APP);
   dialog.dismiss();
}

 

Button for changing Device Database to Cloud Database imagetarge

November 11, 2013 - 2:33am #8

Vuforia does not have an API to explicitely enable/disable internet connection on your device, as this is more a general Android programming issue;

if you consult the Andrpoid developer guide or search the net you can find some threads discussing this, for instance this one:

http://stackoverflow.com/questions/3930990/android-how-to-enable-disable-wifi-or-internet-connection-programmatically

 

Button for changing Device Database to Cloud Database imagetarge

November 11, 2013 - 2:27am #7

I see... so how to deal with the internet connection?

lets say:

1. First time the app launch = device database= don't need internet connection

2. When user press 'Switch to Cloud' button, database switch to Cloud. If there is no internet connection, then show warning "No internet connection".

3. When user switch back from cloud to device, no internet connection needed

 

Based on your tutorial in

https://developer.vuforia.com/forum/faq/android-how-integrate-cloudreco-imagetargets-sample

internet connection is always needed. 

 

What should I do to turn off and turn on the internet connection? is it possible? (Really need this for my project)

Thank you so much ..

Button for changing Device Database to Cloud Database imagetarge

November 4, 2013 - 12:47am #6

Cloud and Device DBs can co-exist, you don't need to switch between one and the other;

however, if you really want to exclude the Device targets when using the Cloud, you can Deactivate the Device dataset that contains our targets, while starting the TargetFinder (see how the Target FInder is started and stopped in the sample code; the targetFinder is the key class to enable/disable CloudReco);

and viceversa, you can Activate your dataset and stop the target finder when you want to use Device Databases and not Cloud.

Button for changing Device Database to Cloud Database imagetarge

November 3, 2013 - 9:50pm #5

So, I had followed your tutorial in

https://developer.vuforia.com/forum/faq/android-how-integrate-cloudreco-imagetargets-sample

so, now my application will recognize the target from both Cloud database and Device database simultaneously and it needs internet connection to launch the app.

 

Now for my last year project, I want to make a button to change between Device database and Cloud database, the functionallity will be like this:

- First time when app launch:

  databaseDevice=true

  don't need internet connection

  can only recognize from .xml  and .dat

 

-When I press button "change to CLOUD"

  databaseDevice=false

  need internet connection (error if no network)

  can only recognize from cloud

 

Then I realized, the code that changes the CLOUD and DEVICE is not in cpp (QCAR_onUpdate), it is in java (ImageTargets.java) in LoadTrackerTask:


protected void onPostExecute(Boolean result)
        {
            DebugLog.LOGD("LoadTrackerTask::onPostExecute: execution " +
                        (result ? "successful" : "failed"));

            if (result)
            {
                if(databaseDevice==true)
                {
                	updateApplicationStatus(APPSTATUS_INITED);
                }
                else if(databaseDevice==false)
                {
                    updateApplicationStatus(APPSTATUS_INIT_CLOUDRECO);
                }
            }
      }

The APPSTATUS_INITED and APPSTATUS_INIT_CLOUDRECO is what differentiates the CLOUD and DEVICE. If it calls APPSTATUS_INITED first, then it cannot be changed to APPSTATUS_INIT_CLOUDRECO anymore.

Then you suggested to switch dataset in QCAR_onUpdate, isn't switching dataset only for changing between 2 DEVICE databases? I need to switch between CLOUD and DEVICE.. please guide me.. thank you.. 

Button for changing Device Database to Cloud Database imagetarge

November 3, 2013 - 2:13am #4

The QCAR_onUpdate() function is defined in the C++ code (not in Java) and you have a nice eample of how to perform the dataset swap (deactivating one and activating another) in the Image Target sample.

Have a look at that sample code, as it already does what you need (and it also shows how to trigger the swap in C++ from a Java method)

 

Button for changing Device Database to Cloud Database imagetarge

November 1, 2013 - 9:37pm #3

Can you please guide what should I add in QCAR_onUpdate? 

because I think the code that changes device and cloud database is this one in loadTrackerTask (ImageTargets.java) and it cannot be called twice and I have no idea what should I add in QCAR_onUpdate to change between cloud and device..please guide..

protected void onPostExecute(Boolean result)
        {
            DebugLog.LOGD("LoadTrackerTask::onPostExecute: execution " +
                        (result ? "successful" : "failed"));

            if (result)
            {
                if(databaseDevice)
                {
                	updateApplicationStatus(APPSTATUS_INITED);
                }
                else
                {
                	// Done loading the tracker, update application status cloud:
                       updateApplicationStatus(APPSTATUS_INIT_CLOUDRECO);
                }
            }

                   }

 

Button for changing Device Database to Cloud Database imagetarge

October 31, 2013 - 12:58pm #2

You should switch the database in the QCAR_onUpdate() in native code, as otherwise the switch may interfere with QCAR in a non-thread-safe way

 

Log in or register to post comments