Scandit.Activity

Methods related to the currently running activity

Methods

(static) convertToNativeUri(uri: string): Promise

Convert a URI returned by the Scandit API to a native one.

Parameters:
Name Type Description
uri string

The URI which should be converted

Returns:
Promise

Promise which is resolved when the URI has been converted to a native URI

Can return an error with code:

Examples
  • JavaScript
  • ES6
Scandit.Activity.convertToNativeUri('http://localhost:8080/file.pdf')
  .then(function(uri) {
    console.log('Native URI is ' + uri)
  })
  .catch(console.error);
Scandit.Activity.convertToNativeUri('http://localhost:8080/file.pdf')
  .then((uri) => {
    console.log('Native URI is ' + uri)
  })
  .catch(console.error);

(static) getActivityId(): string

Returns the activity id that is required by various platform REST APIs

Returns:
string

The activity id or 0 for activities in local development mode

Examples
  • JavaScript
  • ES6
if (Scandit.Activity.getActivityId() === '0') {
  console.log('Activity running in local development');
}
if (Scandit.Activity.getActivityId() === '0') {
  console.log('Activity running in local development');
}

(static) off(arg: (string | function))

Unbinds event handlers from activity related events.

Parameters:
Name Type Description
arg string | function

Event name or callback function

Examples
  • JavaScript
  • ES6
Scandit.Activity.off('backPressed');
Scandit.Activity.off('backPressed');

(static) on(event: string, callback: function)

Binds event handlers to activity related events. Possible events: backPressed.

Parameters:
Name Type Description
event string

Event name

callback function

Callback function

Examples
  • JavaScript
  • ES6
Scandit.Activity.on('backPressed', function() {
  console.log('The back button was pressed');
});
Scandit.Activity.on('backPressed', () => {
  console.log('The back button was pressed');
});

(static) onReady(callback: function)

Registers a function to execute after the activity is ready.

Parameters:
Name Type Description
callback function

The callback function

Examples
  • JavaScript
  • ES6
Scandit.Activity.onReady(function() {
  console.log('The activity is now ready!');
});
Scandit.Activity.onReady(() => {
  console.log('The activity is now ready!');
});

(static) openUri(uri: string): Promise

Open a URI

Parameters:
Name Type Description
uri string

The URI which should be opened, for example http://www.example.com/file.pdf

Returns:
Promise

Promise which is resolved when the activity is back in the foreground

Can return an error with code:

Examples
  • JavaScript
  • ES6
Scandit.Activity.openUri('http://example.com/file.pdf')
  .then(function() {
    console.log('URI has been opened, now we are back into the activity')
  })
  .catch(console.error);
Scandit.Activity.openUri('http://example.com/file.pdf')
  .then(() => {
    console.log('URI has been opened, now we are back into the activity')
  })
  .catch(console.error);

(static) stop()

Stops the activity and goes back to the activity list

Examples
  • JavaScript
  • ES6
Scandit.Activity.on('backPressed', function() {
  Scandit.Activity.stop();
});
Scandit.Activity.on('backPressed', () => {
  Scandit.Activity.stop();
});

Events

backPressed

Back button press event