Setting up a new project
This is a step-by-step tutorial for getting started connecting users with a new Activity.
In case of problems the library will print (hopefully useful) logs to the console which you can capture with 'adb logcat
'.
Download flock-sdk-android.zip and extract it
Create a new Android project in Eclipse
Include
flock.jar
into the project (screenshots):- Right click on your project in the Package Explorer and select "Properties"
- Choose "Java Build Path", select the tab "Libraries", click on "Add External JARs"
- Select
flock.jar
from the extracted sdk
Enable inline documentation for Eclipse (useful for syntax recommendations and hovering over methods):
- Expand flock.jar in the "Libraries" tab of step 3
- Double click on "Javadoc location" and point to the directory "javadoc" from the extracted sdk
Add your developer-id to
AndroidManifest.xml
, just before</application>
<meta-data android:name="FLOCK_DEVELOPER_ID" android:value="your-developer-id" />
- Add the background-service to
AndroidManifest.xml
, just before</application>
. If the project's package name iscom.example.dice
, the tag would be this:<service android:name="com.flockengine.BackgroundService"> <intent-filter> <action android:name="com.mycompany.mygame.BackgroundService" /> </intent-filter> </service>
- Add permission
INTERNET
toAndroidManifest.xml
, just before</manifest>
:<uses-permission android:name="android.permission.INTERNET"></uses-permission>
- In
YourActivity.java
, extendFlockActivity
instead ofActivity
, and to receive events from the engine add anFlockEventCallback
atonCreate()
public class YourActivity extends FlockActivity implements FlockEventCallback { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Flock.setOnEventListener(this); } public void onFlockEvent(FlockEvent event, int sender_id, String msg) { Log.v("", "new event: " + event + ", sender=" + sender_id + ", msg=" + msg); switch (event) { case SESSION_STARTS: Toast.makeText(this, "Game Starts", Toast.LENGTH_SHORT).show();; startActivity(new Intent(YourActivity.this, Game.class)); break; } } }
That's the basic setup! Now you can connect authenticate users, configure the engine and connect to the servers. You will need to start multiple emulators for testing.
Have a look at the examples to see how it works in action!