Finishing with a call

To ensure that each telephone call is returned to the system when your voice application has finished with it, and the line is freed, use the Call.returnCall() method on the relevant Call object.

The following example makes use of the try–catch–finally structure to handle the calls. Successful calls pass through the try block to the finally block. Calls that receive a WVRHungUpException, indicating that the caller has hungup, are passed straight to the finally block. Calls that encounter some other kind of exception print out some debugging information and are also passed to the finally block. In the finally block the call is returned by invoking the Call.returnCall() method. This frees the resources used by the call.

public class MyVoiceApp extends WVRApplication {
	
  public void voiceMain() throws WVRException {
		
    // Define a reference variable for a Call object, so we avoid
    // creating multiple instances later on in the loop
    Call call = null;
		
    // Create the application properties object
    ApplicationProperties appProperties = new ApplicationProperties();
    appProperties.setApplicationName("app1");
    applicationProperties.setLocale(Locale.US);
		
    // Create the WVR object
    WVR wvr = new WVR(this, appProperties);
		
    // Create a boolean to control the call-handling loop
    private boolean keepTakingCalls = true;
		
    // Create the loop
    while (keepTakingCalls) {
      try{
        // Wait for a call
        call = wvr.waitForCall();
			
        // Handle successful calls
        .
        .
        .
      }
      catch (WVRHungUpException e) {
        // Caller has hung up - ignore exception, application will go to
        // finally block
      }
			
      catch (WVRException e) {
        // Print debugging information
        e.printStackTrace();
      }
			
      finally {
        // Return the call
        call.returnCall();
      }
    }
  }
}