-
Notifications
You must be signed in to change notification settings - Fork 15
Partner Sessions
The PartnerSession API lets you create interactive apps such as games and other shared experiences.
In a Chess app, for example, each game of chess will be a session and each chess move will be a message within that session.
Add this to an activity section in AndroidManifest.xml:
<meta-data
android:name="sneer:session-type"
android:value="chess"/>
That activity will be opened by Sneer when the user starts or opens a chess game session.
Add this to the dependencies section of the build.gradle file in the app folder:
compile 'me.sneer:sneer-android-api:X.Y.Z@aar'
X.Y.Z is the latest version found here. Make sure you are editing the build.gradle file in the app folder. There are others.
In the activity's onCreate() method, it joins the session to receive the session's messages:
session = PartnerSession.join(this, new PartnerSession.Listener() {
@Override
public void onMessage(Message message) {
//Called for every message sent by you and by your partner.
}
@Override
public void onUpToDate() {
//Called when there are no more messages pending in the session.
}
});
PartnerSession.join(...) returns a PartnerSession. In the example above, it is kept in a field.
session.send(object);
You can send Strings, Integers, Longs, arrays, Maps, and Lists. Do not call send() from an activity's onCreate method or it will freeze.
message.wasSentByMe() // Returns true if you sent this message, false if your partner sent it.
message.payload() // Returns the value that was sent.
In the activity's onDestroy() method, it closes the session:
session.close();
The session can still be joined normally by future activities.
The Lizard Spock example app is implemented in a single activity class using the API above.
Visit the Sneer Website and subscribe to our Major Announcements List.