Page tree
Skip to end of metadata
Go to start of metadata

Applications can make communications with each other by calling and sending data. iOS and Android have different ways to handle this. In this guide, we will show you how to do it.

iOS

One of the good features of iOS is binding URL schemes to applications. Using schemes is the only way of calling another app. Multiple schemes can be defined for an app. Built-in apps has their own schemes like "http, mailto, tel". The handlers for these schemes can not be changed. If your URL type includes a scheme that is identical to one defined by Apple, the Apple-provided app is launched instead of your app.

Apple also has a note about the case that two different apps use the same scheme:

Note: "If more than one third-party app registers to handle the same URL scheme, there is currently no process for determining which app will be given that scheme.

There is still no mechanism to check that if an app on App Store uses your scheme even on iOS 8."

Setting URL scheme

You can set schemes of your app via project.json file which is located "config / project.json" . Multiple schemes should be separated by commas.

Checking if URL can be opened

Before calling an app URL should be checked to see if it can be opened or not.

var canOpen = Device.canOpenUrl("myscheme1://");

Calling an App

Application.call() method is used to call an app:

function textButton1_OnPressed(e) {
	Application.call({
		app : "myscheme1://"
	});
}

The method above will call the app that has the scheme “myscheme1”. Also some key value pairs can be sent to other application with data parameter.

Application.call({
	app : "myscheme1://",
	data : {
		'user' : 'name'
	}
});

You can also check applinks.org for mobile deep-linking.

This data parameter is converted into a query string and concatenated with the scheme. You can also use a URL with query strings . But do NOT use data parameter if you use this type of URLs.

Application.call({
	app : "myscheme1://path?key=value&another_key=another_value"
});

Handling the call

When your app is called by another app, Application.onApplicationCallReceived is triggered. The query string parameters can be accessed via "e.data" as a JS object. Similarly, URL is accessed via "e.url".

Application.onApplicationCallReceived = function Global_Events_OnApplicationCallReceived(e) {
	alert(e.url); // returns "myscheme1://path?key=value&another_key=another_value"
	alert(e.data.key); // returns "value"
}

Android

Check if application is installed

Application should be checked whether it is installed on the device before calling it.

var isAppInstalled = Device.isApplicationInstalled("io.smartface.SmartfaceDemo");

Calling an app

On Android side, the package name and activity class name is needed to call an app. You can find these values in "AndroidManifest.xml".

An App to be called, should be defined as "PACKAGE_NAME|CLASS_NAME" format.

function textButton1_OnPressed(e) {
	Application.call({
		app : "io.smartface.SmartfaceDemo|io.smartface.SmartfaceDemo.A"
	});
}

You can send data with data parameter like iOS.

function textButton1_OnPressed(e) {
	Application.call({
		app : "io.smartface.SmartfaceDemo|io.smartface.SmartfaceDemo.A",
		data : {
			'key' : 'value'
		}
	});
}

Data key value pairs are added to the Intent as extra string parameters.

Handling the call

When your app is called by another app, Application.onApplicationCallReceived is triggered. Intent extra string parameters can be accessed via e.data as a JS object.

Application.onApplicationCallReceived = function Global_Events_OnApplicationCallReceived(e) {
	alert(e.data.key); // returns "value"
}

Assume that there are two apps, the first app calls the second app, then the second app finishes it’s job and returns back to the first app. These two actions can be handled separately on Android side. There is  e.eventType parameter in Application.onApplicationCallReceived event. This can be “call” or “callback”. When the first app calls the second one, e.eventType returns “call” in the second app’s Application.onApplicationCallReceived event. Then, we call Application.callFinish() method. The second app finishes and goes back to the first app. In the first app’s Application.onApplicationCallReceived method e.eventType returns “callback” so that you can understand if the app is called directly or through a "callback".

The code below is for the second app :

Application.onApplicationCallReceived = function Global_Events_OnApplicationCallReceived(e) {
	if (e.eventType === "call") {
		alert(e.data.data_from_first_app);
	}
}

And the code below is for the first app, after the second app calls Application.callFinish() method.

Application.onApplicationCallReceived = function Global_Events_OnApplicationCallReceived(e) {
	if (e.eventType === "callback") {
		alert(e.data.data_from_second_app);
	}
}

For Android, Application.callFinish() method takes no parameter. For iOS, works like Application.call() method and does the same job.