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

 This guide explains how to create and use Android plugins in Smartface.

Android Plugin – Hello World

 Placing AndroidPluginTemplate.zip

Firstly lets download AndroidPluginTemplate.zip (You can download it from here).

Unzip AndroidPluginTemplate, it will include a folder named io:

Create an app on Android Studio, and put this io under "app/src/java" folder.


Configurations

Now under the “Gradle Scripts” open “build.gradle(Module: app)” and make sure that in the dependencies compile is as below:

build.gradle
compile 'com.android.support:appcompat-v7:24+'
compile 'com.google.android.gms:play-services:9.4.0'


Another thing that must be checked is about AppTheme. Under res->values->styles there are two XML files. Open both of them and check if there is any styleName defined. If there is a styleName, it’s parent must be “Theme.AppCompat” (or descendant) as below:

 Creating PluginConfig.JSON

PluginConfig.JSON will be placed under Assets folder, so firstly lets create an Assets folder:

And now, inside this assets folder create a new file and name it as "PluginConfig.JSON":

And now write your class package {“classes”:[“com.birfincankafein.helloplugin.HelloNotifier”]} inside this file as below:

Adding New Class

Lets create a new class and name it as HelloNotifier:

And also in MainActivity add some codes just for testing:

That was just one simple class example.

Make sure you test your all classes, and your project and also make sure it works native before you deliver it. Furthermore, when you finish developing your native Android app, test all of its components before compile.

Creating New Key

You will need a key, you can use your existing one or create a new one as below:


The new key will be placed in:

Building APK

Now you can make sure your APK compile build and you can test the functionality.

Generating Android Plugin

You can generate plugin using Smartface CLI (Command Line Interface tool). For more information and installation instructions, visit the CLI page.

Run “smfc -i” command from terminal to start generating plugin.

Now place "package.json" file inside to your project folder.

This is the path for “Android Plugin Project”:

This is path for your "apk" file.

After you enter Plugin project APK, CLI will start to generate Android plugin as above:

When plugin is ready, CLI will show this message above “Your plugin is ready!”. It will be named as output.zip (in your project folder).

Usage of new plugin in Smartface

Place this new plugin under plugin folder of your workspace.

After that , write your plugin definitions to project.json file.

After that write code into Smartface,

var buttonSayHello = new SMF.UI.TextButton({
		name: "buttonSayHello",
		text: "Say Hello",
		onPressed: function(){
			HelloNotifier.sayHello("Landroid/content/Context;");
		},
		left: "15%",
		top: "35%",
		width: "70%",
		height: "10%"
	});
page1.add(buttonSayHello);
	
var buttonSayHelloParameter = new SMF.UI.TextButton({
	name: "buttonSayHelloParameter",
	text: "Say Hello with Parameter",
	onPressed: function(){
		HelloNotifier.sayHelloWithParameter("This is awesome!","Landroid/content/Context;");
	},
	left: "15%",
	top: "55%",
	width: "70%",
	height: "10%"
});
Pages.page1.add(buttonSayHelloParameter);

When button (buttonSayHello) is pressed, it will toast “Hello from Smartface Plugin!”. And will look like as in the below screenshot:


When button (buttonSayHelloParameter) is pressed, it will toast “Hello with parameter: This is awesome!". And will look like as in the below screenshot: