Skip to main content
Version: Next

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.

import Application from ('@smartface/native/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.

Application.restart = (): void => {
Data.setBooleanVariable("isApplicationRestart", true);
Application.restart();
};
if (
System.OS === System.OSType.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.

TypeScript

Linking.openURL({
uriScheme: "smartface-emulator://",
data: {
testString: encodeURIComponent("Smartface Native Framework"),
testBoolean: true,
testNumber: 1.13
},
onSuccess: function () {
alert("Application call completed")
},
onFailure: function () {
alert("Application call failed")
}
});

// Calling an application for myscheme-one with chooser dialog and title.
Linking.openURL({
uriScheme: "myscheme-one://",
data: {
testString: encodeURIComponent("Smartface Native Framework"),
},
onSuccess: function () {
alert("Application call completed")
},
onFailure: function () {
alert("Application call failed")
},
isShowChooser: true,
chooserTitle: "Select 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);

//@ts-ignore
// 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.

TypeScript
Application.onApplicationCallReceived = (e: {
data: { [key: string]: any };
}): void => {
alert({
title: "onApplicationCallReceived",
message: JSON.stringify(e),
});
};

Application.on('exit', () => {
alert("onExit");
});

Application.on('maximize', () => {
alert("onMaximize");
});

Application.on('minimize', () => {
alert("onMinimize");
});

Application.android.onRequestPermissionsResult = (e: {
requestCode: number;
result: boolean;
}): void => {
alert({
title: "onRequestPermissionsResult",
message: JSON.stringify(e),
});
};
Application.on('unhandledError', (e: UnhandledError) => {
const error = errorStackBySourceMap(e);
const message = {
message: System.OS === System.OSType.ANDROID ? error.message : e.message,
stack: error.stack
};
if (message.stack) {
console.error('Unhandled Error: ', message);
alert(JSON.stringify(message, null, 2), e.type || 'Application Error');
}
});