Swarm Documentation API Reference
Getting Started with the Swarm SDK on AndroidEstimated Integration Time: 10 minutes
This guide provides step-by-step instructions for quickly integrating the Swarm SDK into an Android game or application. For convenience, the Swarm SDK is a library project. For more information about library projects click here.
In this guide we show you how to get started and setup Swarm in your app. After completing these steps, you'll be ready to add Leaderboards, Achievements, Cloud Data Saves, Virtual Stores and more! If you need help or run into issues while integrating social features, please visit the Swarm Support Center. Finally, if you're using the Unity Plugin, then please refer to the Unity Plugin Docs instead. Prerequisites:
Step 1: Import and Link the Swarm Library
Step 2: Set Manifest Merger FlagAdd this line to the bottom of your app's project.properties file:manifestmerger.enabled=true Step 3: Extend SwarmActivityFor Swarm to properly respond to requests, all activities in your app must extend SwarmActivity instead of Activity (SwarmActivity extends Activity). Note that the SwarmActivity class behaves the same as the Activity class, but it also does some work for you behind the scenes to manage interactions with Swarm.
public class MyActivity extends Activity {
public class MyActivity extends SwarmActivity {
[+] Important! Click here if you're using a library or framework that doesn't allow you to extend SwarmActivity (i.e. LibGDX, AndEngine, or the NDK).Step 4: Setup your App in the Admin Panel
Step 5: Initialize SwarmYou will need to initialize Swarm at every entry point into your app, typically this is in your main activity's onCreate() method. Add the following line of code in your main Acitiviy's onCreate() method and replace SWARM_APP_ID and "SWARM_APP_KEY" with your App ID and App Key from the Admin Panel.Swarm.init(this, SWARM_APP_ID, "SWARM_APP_KEY");[+] Click here to see more control and customization options. (Optional) Add a Swarm Dashboard Entry PointAn entry point into Swarm's Dashboard can easily be attached to a button.
Button myButton = (Button)findViewById(R.id.my_swarm_button);
myButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Swarm.showDashboard();
}
});
Many entry points into Swarm are available. The methods below will display the Login, Leaderboards, Achievements, and Store screens.
Swarm.showLogin(); Swarm.showLeaderboards(); Swarm.showAchievements(); Swarm.showStore(); (Optional) Launching on the Amazon AppStoreTo make your game or app compatible with the Amazon Appstore (or another app store outside of Google Play), simply call the following method just before calling Swarm.init(...);Swarm.enableAlternativeMarketCompatability(); Congratulations!Your app now has the basic infrastructure required for Swarm! It's time to add some social features. You can add Leaderboards, Achievements, Cloud Data Saves, Virtual Stores and more! All features are completely modular and can be added in any order.All features can be quickly integrated using Swarm's pre-built screens and toasts, but full APIs are available if you prefer to customize the features to match your game or app's look and feel. |

