Guild Wars 2 WvW API Usage in Android

Another android code sample that can get the active match-ups from the Guild Wars 2 WvWvW API, parse them all and store in a local cache.

First thing you need to do is create the helper class called Utils, create a file called Utils.java and insert the following code:

Next you will need to create the ObjectiveInfo class file – Create a class called ObjectiveInfo and paste in the following code :

Now we have the base ObjectiveInfo class done, let’s move on to the MatchupCache class which will store all the current matchups returned from the Guild Wars 2 API.

Create a class called MatchupCache and paste in the following code:

This class stores ALL the match-ups from the GW2 API. You can easily add a filter for EU or US servers – Check if the WorldIDs are above 2,000 for EU, or below for US.

Last thing we need is the JSONFunctions class which is the same as the previous post without the API key code. Create a new class called JSONFunctions and paste in the following code:

Now to establish the cache we need to do:

You’ll need the last two files which can be downloaded here. This zip contains the assets (gw2_objectives.json + gw2_worlds.json) that go inside your projects assets folder.

Make sure to run this in a AsyncTask for example and not inside the main OnCreate else your app will freeze for a while without anything happening on screen – Causing users to believe your application has frozen.

Final Note: Read up about the JSON structures returned on the official Guild Wars 2 API here. Specifically under Version 1 Endpoints – World vs World

Leave a Comment