Velocity API: Action.launchForResult()

Version 2

    Return To Index

    Action.launchForResult()

    Overview

    Launches an Android Activity that allows the Client to interact with other software loaded on the device.

    Calls to Action.launchForResult() are asynchronous and the script will continue to execute even through the activity has not returned. . The function passed as the second parameter will be invoked when the activity completes. Only one outstanding Activity launched for result should be active at a time.

    Activities are started using intents. The intent is represented as a JavaScript object with certain properties.

    • Intents must have at least an action or a class and package combination.
    • If multiple applications match the intent, a chooser dialog will appear.

    Format

     

    var resultCallback = function(resultIntent) { /*...*/ }; 
    Action.launchForResult(intent, resultCallback);
    ParameterDescriptionTypeRequired
    intentDescribes the activity or action and associated information.ObjectRequired
    resultCallbackA callback used when the activity returnsFunctionRequired
    resultIntentDescribes the results of the activity or action. This is a parameter for resultCallback.ObjectRequired

     

    Intent object properties

     

    ValueDescriptionTypeRequiredNotes
    actionA string representing the action to be performed.StringOptionalIf the device has multiple apps registered to handle an action, a chooser dialog appears.
    categoriesA list of required categories for the activity that is being started.Array of stringsOptional
    classThe name of the activity class to explicitly launch.StringOptionalMust be used with package.
    packageThe name of the application package to explicitly launch.StringOptionalMust be used with class.
    extrasPasses additional data to the invoked app.Array of objectsOptionalIf you use extras, you must use an array to specify the name, value, and type (string or integer) for the data. For example:
    extras: [{name:'scanMode', value:'SCAN_MODE', type:'string'}]
    resultA number representing the returned result from the launched activity.NumberRequired in the resultIntentA value of -1 indicates that the operation succeeded. A value of 0 indicates the operation was canceled. Values of 1 or greater indicate custom defined values for the result of the operation.

     

    Example

    /* Launch Barcode scanning application, send results as * a scan to the host. 
    */
      
    Action.launchForResult({
         action: 'com.google.zxing.client.android.SCAN',
         extras: [
              {name:'scanMode', value:'SCAN_MODE', type:'string'}
          ]
    },
    function (intent) {
         if(intent.result === -1) {
              var scanData;
              var scanType;
              for(var extra in intent.extras) {
                   if(intent.extras[extra].name === 'SCAN_RESULT')
                        scanData = intent.extras[extra].value;
                   if(intent.extras[extra].name === 'SCAN_RESULT_FORMAT')
                        scanType = intent.extras[extra].value; }
              if(scanData && scanType) {
                   Device.fakeScan(scanType, scanData);
                  }
              }
         }
    );