Skip to content

Android SDK Setup

Prateek edited this page Jul 12, 2017 · 48 revisions

We are working on setting up our Nexus Repositories. Please download our AAR bundles to integrate our Android SDK.

To integrate the Android SDK

Step 1

Download Core Library

Download AppsFlyCore.AAR

Core library has all the libraries to run Appsfly Plugins.

Step 2

Download MicroApp Library

Download AppsFlyMicroApps.AAR

This library has the dependency on Core Library. This will enable developer to fly in MicroApps into the user's context of his application.

Note: If MicroApps are not used in the publisher application, skip Step 2.

Step 3

Add the dowloaded libraries as modules to the parent android project.

Add Core and MicroApp libraries individually as modules in the project structure.

Goto Project Structure -> Add module (+)

Step 4

Add Dependencies to your main module's gradle file

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.squareup.duktape:duktape-android:1.1.0'
compile 'net.steamcrafted:materialiconlib:1.1.3'
compile 'com.android.support:design:25.3.1'
compile('io.socket:socket.io-client:0.8.3') {
    exclude group: 'org.json', module: 'json'
}
compile project(':core_v-0-1-1')
compile project(':micro-app_v-0-1-1')

Skip step 3 if MicroApp SDK is not included. Also, if a support dependency is already added to the project, be sure to exclude from above. Note: Our Nexus repo will be setup soon for managing these dependencies.

Step 5

Initialize runtime with MicroApp configurations

Override your Application's Instance onCreate() method

@Override
public void onCreate() {
	super.onCreate();
	String repoUrl = "REPO_URL"; // Current repo url is 'http://s3-ap-southeast-1.amazonaws.com/repo.appsfly.io'
	String projectId = "PROJECT_ID"; // Project under which MicroApp is created
	String microAppId = "MICROAPP_ID"; // MicroApp Id
	String associationKey = "YOUR_ASSOCIATION_KEY"; // Association key created on the dashboard

	ArrayList<AppsFlyClientConfig> appsFlyClientConfigs = new ArrayList<AppsFlyClientConfig>();
	AppsFlyClientConfig appsflyConfig = new AppsFlyClientConfig(projectId, microAppId,  associationKey, repoUrl);
	appsFlyClientConfigs.add(appsflyConfig);
	AppsFlyProvider.getInstance().initialize(appsFlyClientConfigs, this);
}

Note: This will start the process of syncing Metadata required to run MicroApp in your application. PROJECT_ID, MICROAPP_ID & ASSOCIATION_KEY can be obtained from MicroApp Service Provider.

Step 6

Fly in MicroApp into context of user

To launch the MicroApp, run the following snippet where there is a call to action.

AppsFlyProvider.getInstance().pushApp("MICROAPP_ID", "ASSOCIATION_ID", "INTENT", new JSONObject(){"USER_CONTEXT_IN_JSON_FORMAT"}, context);

Note: This will create an overlay activity showing the MicroApp.


Data into and out of MicroApp

To put data into the MicroApp:

//Put user context data inside a JSONobject and pass it as intent data.
JSONObject userContextData = new JSONObject();
data.put(*key* , *value*);
String intentString = "INTENT";
AppsFlyProvider.getInstance().pushApp("MICROAPP_ID", "ASSOCIATION_ID", intentString", userContextData, context);

To retrieve data from the MicroApp:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK && requestCode == AppsFlyProvider.REQUEST_CODE) {
        String dataStr = data.getStringExtra("result");
        JSONObject resultData;
        try {
            resultData = new JSONObject(dataStr);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        //Get values from resultData with keys specified by the MicroApp Service Provider .
        Object value1 = result.get(*key1*);
        String value2 = result.getString(*key2*);
    }
}

Note:

Currently, this documentation is in beta phase and is being updated regularly. It aims to ensure a smooth integration of AppsFly SDK into your projects. For any suggestions or to report any issues with the information mentioned here, please contact [email protected]

-Team AppsFly.io

Clone this wiki locally