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

This guide explains how to use "Inter-app communication and interaction with URL Schemes and Intents" and differences between iOS and Android devices.

What is Inter-app communication ?

In order to perform Inter-app communication, we use the Application.call method. You cannot only launch another application but also pass data to it.

Usage

First of all, you need to have two different workspace which are using different bundle identifiers. ( such as : io.smartface.app1 , io.smartface.app2 )

For application call, we will need two different applications with different applicationIDs.

We can use "io.smartface.appcall1" for the first application and "io.smartface.appcall2" for the second application.

2.1 First Example

Let's make a simple example which only launches an application from another one. iOS and Android have some differences for the usage of Application.call method.

Android

For the first application that we are going to create, let's use the code block below :

var myLabel = new SMF.UI.Label({
	top : "5%",
	height : "5%",
	left : "0%",
	width : "100%",
	text : "1st Application"
});
myLabel.textAlignment = SMF.UI.TextAlignment.CENTER;
var myButton = new SMF.UI.TextButton({
	top : "40%",
	left : "15%",
	width : "70%",
	height : "15%",
	text : "Call 2nd app",
	onPressed : function () {
		Application.call({
			app : "io.smartface.appcall2|io.smartface.appcall2.A" // These BundleID's are owned by the application which you would like to call.
		});
	}
});
page1.add(myLabel);
page1.add(myButton);

And for the second application, add the following code block :

var myLabel = new SMF.UI.Label({
	top : "5%",
	height : "5%",
	left : "0%",
	width : "100%",
	text : "2nd Application"
});
myLabel.textAlignment = SMF.UI.TextAlignment.CENTER;
var myButton = new SMF.UI.TextButton({
	top : "40%",
	left : "15%",
	width : "70%",
	height : "15%",
	text : "Call 1st app",
	onPressed : function () {
		Application.call({
			app : "io.smartface.appcall1|io.smartface.appcall1.A" // These BundleID's are owned by the application which you would like to call.
		});
	}
});
page1.add(myLabel);
page1.add(myButton);

 

 

As you see in pictures above, when you press the “Call 2nd App” button in 1st application, it launches the second application and vice versa.

iOS
Tip: You need to create a tracker instance for iOS. 

Let's make a simple example for iOS also, which launches another application. For iOS, it is a bit different to call an application.
First, open a new workspace, that will be the first application. Open project.json file under config folder. There is a field called URL Schemes.
Lets fill this with “schemeOfFirstApp” as seen in the picture below:

Now add the code block below :

 

var myButton = new SMF.UI.TextButton({
	top : "40%",
	left : "10%",
	width : "80%",
	height : "15%",
	text : "Call 2nd application",
	onPressed : function () {
		Application.call({
			app : "schemeOfSecondApp://"
		});
	}
});
page1.add(myLabel);
page1.add(myButton); 

For the second application, open a new workspace. After that, open project.json file under config folder. There is a field called URL Schemes.
Let's fill this with “schemeOfSecondApp” .

For the second application add the code block below :

var myButton = new SMF.UI.TextButton({
	top : "40%",
	left : "10%",
	width : "80%",
	height : "15%",
	text : "Call 1st application",
	onPressed : function () {
		Application.call({
			app : "schemeOfFirstApp://"
		});
	}
});

Also add these two objects to the related page. 

Now, let's see the result. We will have two different applications, with different bundle id’s, and they will call each other.


Press the button “Call 2nd application” in first application, it will launch the second one, and vice versa.

Second Example

Now, let's see how can we send data between two different applications.

Android

Again, we are going to create two different projects. For the first one, use the below code block :

var myLabel = new SMF.UI.Label({
	top : "5%",
	height : "5%",
	left : "0%",
	width : "100%",
	text : "1st Application"
});
myLabel.textAlignment = SMF.UI.TextAlignment.CENTER;
var myButton = new SMF.UI.TextButton({
	top : "40%",
	left : "10%",
	width : "80%",
	height : "15%",
	text : "Send data to 2nd app and call it",
	onPressed : function () {
		Application.call({
			// The first one is package name and the second one is activity name.
			app : "io.smartface.appcall2|io.smartface.appcall2.A", 
			data : '{"user":"myname","pass":"mypass"}'
		});
	}
});
page1.add(myLabel);
page1.add(myButton);

For the second application, you need to use the code block below :

Application.onApplicationCallReceived = function (e) {
	alert("e : " + JSON.stringify(e.data));
}

Add the above code inside app.js. This is used in order to get the sent data by first application;

As you see, from the first application, data is sent and as a result, when the second application launched, it alerts this data.

iOS

Now, let's make a similar example for iOS, which will be able to not only launch another application but also send data to it. Be careful about the URL Schemes field, you should always fill it for iOS application call, and call the app using this URL Schemes value. (For the first application fill this field with “schemeOfFirstApp” and for the second application fill this field with “schemeOfSecondApp”). For the first application, use the below code. It creates a dynamic textButton, and when it is pressed, calls the second application and sends data(123456).

var myButton = new SMF.UI.TextButton({
	top : "40%",
	left : "10%",
	width : "80%",
	height : "15%",
	text : "Call 2nd application",
	onPressed : function () {
		Application.call({
			app : "schemeOfSecondApp://?data=123456"
		});
	}
});
page1.add(myButton);

For the second application use the code below :

var myButton = new SMF.UI.TextButton({
	top : "40%",
	left : "10%",
	width : "80%",
	height : "15%",
	text : "Call 1st application",
	onPressed : function () {
		Application.call({
			app : "schemeOfFirstApp://?data=987654"
		});
	}
});
page1.add(myButton);

And, add this code block below for the two applications(both for the first application and the second one )  :

Application.onApplicationCallReceived = function (e) {
	alert("e : " + JSON.stringify(e.data));
}

Open the first application, press button “Call 2nd application”, as you see below, the second app will be launched and data is sent.

Now open the second application, press the button called “Call 1st application”. Aapp : "io.smartface.appcall2|io.smartface.appcall2.A"s you see, first application will launch and data will be sent.