Game Hack Day NYC
FTW

Client Library .jar Download

Signup/Login Ignore link in email, I’ll manually enable the accounts you create! You’ll need to grab the Dev API key and create a new Game Key when logged in.

App Download Required for use on device. Tethers device to user account. Will need to create a new user account on device. User/Developer accounts are separate.

Demo Game Check out this open source game to see how it works.

If you need any help, have any questions, or most importantly, have feedback, shoot an email to support@getftw.com.

FTW Android Client Library Notes:

  1. Add the jar to your project

    For example under eclipse ( Galileo ) …

    a. Right click your project in the package explorer

    b. Choose ‘Properties’

    c. Choose ‘Java Build Path’

    d. Select the ‘Libraries’ tab

    e. Click ‘Add External JARs…’

    f. Locate the FTW library jar and click open

    g. You should now see ‘ftwlib.jar - ’ added to the list of libraries present

  2. The FTW library requires some permissions, add these to your manifest.xml …

     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
     <uses-permission android:name="android.permission.BATTERY_STATS" />
     <uses-permission android:name="android.permission.WRITE_SETTINGS" />
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  3. Declare the FTW service in your manifest.xml by adding the following …

     <service android:name="com.ftw.android.library.FTWService">
       <intent-filter>
         <action android:name="com.ftw.android.library.IFTWService"/>
       </intent-filter>
     </service>

    This goes inside the application tag as in the following example …

     <application ...>
       ...
       <service android:name="com.ftw.android.library.FTWService">
         <intent-filter>
           <action android:name="com.ftw.android.library.IFTWService"/>
         </intent-filter>
       </service>
     </application>
  4. Import the library classes in any java file making FTW library calls etc. …

     import com.ftw.android.library.*;
  5. To start the library, call the following …

     FTWAPI ftwAPI = new FTWAPI(this.getBaseContext(), <apiKey>, <applicationId>);

    Replacing

    HTML parse error: 
    <apiKey> with a string representing your api key, this doesn't change, you can use the same one for as many applications as you like, and replace <applicationId> with a string representing your application id for this particular application, application ids need to be unique on an application by application basis else you may overwrite save data for one of your other applications.

  6. To finish with the library, do the following …

     ftwAPI.shutdown();
     ftwAPI = null;

    This will unbind you from the service, allowing the OS to free up resources once everyone’s finished with the service.

  7. All further API calls rely on the service being up and running, and therefore must be called after onCreate in your activity has finished, otherwise they will cause a block whilst waiting for the service to start, which it doesn’t until onCreate has finished.

  8. To log the user in, use …

     boolean bLoggedIn = ftwAPI.login();

    Returns true if login was successful, else false if something has gone wrong or the user hasn’t already logged in via the app.

  9. To write save data, do …

     boolean bWriteSuccessful = ftwAPI.write(<saveDataString>);

    Replacing

    HTML parse error: 
    <saveDataString> with a string representing your save data.

    For example …

     JSONObject json = new JSONObject();
     json.put("map.id", mCurrentMap);
     String saveDataString = json.toString();
     boolean bSuccess = ftwAPI.write(saveDataString);
  10. And to read back save data, do …

    String saveDataString = ftw.read();

    saveDataString will hold the same string written by the last call to write(), or returning null if there’s been an error or there’s no previous save data.

    For example …

    String saveDataString = ftwAPI.read();
    JSONObject json = new JSONObject(saveDataString);
    int mapID = json.getInt("map.id");