Application

API Reference: Application

Application is a set of collection for application based properties and methods

Properties

The properties of Application are:

byteReceived

The received bytes from the application.

byteSent

The sent bytes from the application.

currentReleaseChannel

The specified release channel within config/project.json.

packageName

Application package name. This is Android specific property.

smartfaceAppName

The application name within config/project.json.

version

The application version within project.json.

JavaScript
JavaScript
const Application = require('sf-core/application');
console.log("Application.byteReceived: " + Application.byteReceived);
console.log("Application.byteSent: " + Application.byteSent);
console.log("Application.currentReleaseChannel: " + Application.currentReleaseChannel);
console.log("Application.android.packageName: " + Application.android.packageName);
console.log("Application.smartfaceAppName: " + Application.smartfaceAppName);
console.log("Application.version: " + Application.version);

Methods

The methods of Application are:

call

Launches another application and passes data. Data object should be a key-value object and you should encode the data that you want to send. Acceptable types in the data object are encoded number, string and boolean. For Android, you can open application chooser with isShowChooser parameter and set chooser dialog title with chooserTitle. If an app can open a given URL resource onSuccess callback will be triggered otherwise onFailure will be triggered.

checkPermission

This function checks if one of the dangerous permissions is granted at beginning or not. For Android versions earlier than 6.0, it will return value exists in manifest or not. For permissions in the same category with one of the permissions is approved earlier, checking will return as it is not required to request for the same category permission. This is Android specific property.

exit

Exits from the application.

requestPermissions

With requestPermissions, the System Dialog will appear to ask for permission grant by the user for dangerous (privacy) permissions. onRequestPermissionsResult will be fired after user interact with permission dialog. This is Android specific property.

restart

Restarts the application. When app is restarted app.js is triggered again and if any Plugins are used existingly; must be checked before required.

JavaScript
JavaScript
Application.restart = function(restart) {
Data.setBooleanVariable('isApplicationRestart', true);
restart();
}.bind(null, Application.restart);
if (System.OS === "Android" || !Data.getBooleanVariable('isApplicationRestart')) { // Should check when initialize plugin for iOS
require("./appStart/firebase");
require("./appStart/instabug");
require("./lib/fabric");
}
else {
Data.setBooleanVariable('isApplicationRestart', false);
}

shouldShowRequestPermissionRationale

This method checks for a permission is shown before to user and the program is about to request the same permission again. Android explains this on Developers Android on section Explain why the app needs permissions as "For example, if you write a camera app, requesting the camera permission would be expected by the user and no rationale for why it is requested is needed. If however, the app needs a location for tagging photos then a non-tech savvy user may wonder how location is related to taking photos. In this case, you may choose to show UI with the rationale of requesting this permission.". This is Android specific property.

JavaScript
JavaScript
const Application = require('sf-core/application');
// Calling Smartface Emulator
Application.call("smartface-emulator://",{
testString: encodeURIComponent("Smartface Native Framework"),
testBoolean: encodeURIComponent(true),
testNumber: encodeURIComponent(1.13)
}, function(){
console.log("Application call completed");
}, function(){
console.log("Application call failed");
});
// Calling an application for myscheme-one with chooser dialog and title.
Application.call("myscheme-one://",{
testString: encodeURIComponent("Smartface Native Framework"),
}, function(){
console.log("Application call completed");
}, function(){
console.log("Application call failed");
}, true, "Choose an application");
// Checking ACCESS_FINE_LOCATION permission
console.log("Application.android.checkPermission(ACCESS_FINE_LOCATION): " + Application.android.checkPermission(Application.android.Permissions.ACCESS_FINE_LOCATION);
// Closing application
Application.exit();
// Restarting application
Application.restart();
// Requesting ACCESS_FINE_LOCATION permission
Application.android.requestPermissions(1002, Application.android.Permissions.ACCESS_FINE_LOCATION);
// Checking if you should show dialog about why application needs this permission
console.log("Application.android.shouldShowRequestPermissionRationale: " + Application.android.shouldShowRequestPermissionRationale(Application.android.Permissions.ACCESS_FINE_LOCATION));

Events

The events of Application are:

onApplicationCallReceived

Triggered when the application is called by another application.

onExit

Triggered before exiting the application.

onMaximize

Triggered after the application in the foreground state. In Android, it triggered even the user is leaving another activity(even the activities launched by your app). That means Permissions & derived from Dialog components are makes this callback to triggered

onMinimize

Triggered after the application in the background state. Background state means that user is in another app or on the home screen. In Android, it triggered even the user is launching another activity(even the activities launched by your app). That means Permissions & derived from Dialog components are make this callback to triggered.

onRequestPermissionsResult

This event is called after Application.android.requestPermissions method. This event is fired asynchronous way, there is no way to make sure which request is answered. This is Android specific property.

onUnhandledError

Triggered when a unhandled error occurs.

JavaScript
JavaScript
const Application = require('sf-core/application');
Application.onApplicationCallReceived = function(e){
alert({
title: "onApplicationCallReceived",
message: JSON.stringify(e)
});
};
Application.onExit = function(e){
alert("onExit");
};
Application.onMaximize = function(){
alert("onMaximize");
};
Application.onMinimize = function(){
alert("onMinimize");
};
Application.android.onRequestPermissionsResult = function(e){
alert({
title: "onRequestPermissionsResult",
message: JSON.stringify(e)
});
};
Application.onUnhandledError = function (e) {
alert({
title: lang.applicationError,
message: e.message + "\n\n*" + e.sourceURL + "\n*" + e.line + "\n*" + e.stack
});
};