Samsung Chord and Group play SDK Wei Xiao, Technical Evangelist

Building Collaborative and Interactive Apps with
Samsung Chord and Group play SDK
Wei Xiao, Technical Evangelist
Media Solution Center America
#SDC13
What’s Samsung Chord?
Samsung Chord
Samsung Chord Features
 Enable reliable, peer-to-peer communication across
connected devices, without the need of a server
 Connection: WiFi, Mobile hotspot, WiFi Direct
 Group Management: Manage multiple device groups
in a local network
 Messaging Framework: Real-time data transfer
across a group of devices(text messages, binary data
and files)
Samsung Chord
 Group Management
– Easy device discovery and connection
– Devices can join and leave a group any time
– Several individual groups in a local network
Local network
Group B
Sharing
Pictures
Group A
Multiplayer
Game
A
B
C
D
Samsung Chord
 Messaging Framework
– Data transfers to all or selected devices in the same group
– Data can be encrypted - New
– Design your own protocol easily
Samsung Chord
Use Case 1: Multi-player Game – Air Hockey
Use Case 2: Education
Use Case 3: Game Control
Use Case 4: Proximity based social networking
Use Case 5: Integration with other Samsung technologies
Node & Channel
 Node: A device that connects to other devices through Chord protocol.
 Channel: A logical device group
- public channel
- private channel
Chord Architecture
* Android 4.0 (Ice Cream Sandwich API 14) or above support Chord.
Samsung Chord
Components
Components:
•
chord-v1.5.0.jar
•
libchord-v1.5.so
Imported package:
com.samsung.android.sdk.chord
Android Manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Class Diagram
Air Hockey
Air Hockey - 1. Start game
Air Hockey - 1. Start game
Initialize Chord
Schord chord = new Schord();
try {
// Initialize an instance of Schord
chord.initialize(this);
} catch (SsdkUnsupportedException e) {
if(e.getType()==SsdkUnsupportedException.VENDOR_NOT_SUPPORTED) {
// Vendor is not Samsung
}
}
Air Hockey - 1. Start game
Create Chord Manager instance
mChord = new SchordManager(this);
mChord.setLooper( getMainLooper() );
List<Integer> interfaceList = mChord.getAvailableInterfaceTypes();
if (interfaceList.isEmpty()) {
// There is no connection
return;
}
Air Hockey - 1. Start game
Select network interface
mChord.start(interfaceList.get(0).intValue(), new SchordManager.StatusListener(){
@Override
protected void onStarted ( String nodeName, int reason ){
// Called when Chord starts successfully.
// Ready for handling channels
}
@Override
protected void onStopped ( int reason ) {
}
}};
Air Hockey - 1. Start game
Register Chord Manager Listener
mChord.start(interfaceList.get(0).intValue(), new SchordManager.StatusListener(){
@Override
protected void onStarted ( String nodeName, int reason ){
// Called when Chord starts successfully.
// Ready for handling channels
}
@Override
protected void onStopped ( int reason ) {
// Called when Chord stops.
}
}};
Air Hockey - 1. Start game
Air Hockey - 1. Start game
Join Channel
mChord.joinChannel(“com.samsung.multiairhockey.CHANNEL”,
new SchordChannel.StatusListener(){
@Override
protected void onNodeJoined ( String fromNode, String fromChannel ){
// called when a node joins a channel
}
@Override
protected void onNodeLeft ( String fromNode, String fromChannel ){
// called when a node leaves a channel
}
});
Air Hockey - 1. Start game
Register Channel Listener
mChord.joinChannel(“com.samsung.multiairhockey.CHANNEL”,
new SchordChannel.StatusListener(){
@Override
protected void onNodeJoined ( String fromNode, String fromChannel ){
// called when a node joins a channel
}
@Override
protected void onNodeLeft ( String fromNode, String fromChannel ){
// called when a node leaves a channel
}
});
Air Hockey - 1. Start game
Air Hockey - 2.Pairing
Air Hockey - 2. Pairing
SchordChannel channel =
mChord.getJoinedChannel(“com.samsung.multiairhockey.CHANNEL”);
byte[][] payload = new byte[1][];
payload[0] = “LEFT”.getBytes();
// void sendDataToAll ( String payloadType, byte[][] payload );
channel.sendDataToAll(“JOIN_REQUEST”, payload);
Air Hockey - 2. Pairing
mChord.joinChannel(“com.samsung.multiairhockey.CHANNEL”,
new SchordChannel.StatusListener(){
@Override
protected void onDataReceived( String fromNode, String fromChannel,
String payloadType, byte[][] payload){
if( playloadType.equals(“JOIN_REQUEST”)){
String pos = new String( payload[0] );
}
}
});
Air Hockey – 2. Pairing
Air Hockey - 2. Pairing completes
Air Hockey - 3. Shooting
Air Hockey - 3. Shooting
SchordChannel channel = mChord.getJoinedChannel ( channelName );
byte[][] payload = new byte[1][];
payload[0] = “{0,5}”.getBytes();
for (String node : mInGameNodes ){
// void sendData ( String toNode, String payloadType, byte[][] payload );
channel.sendData( node, “BALL_COORD”, payload);
}
Air Hockey - 3. Shooting
mChord.joinChannel(“com.samsung.multiairhockey.CHANNEL”,
new SchordChannel.StatusListener(){
@Override
protected void onDataReceived( String fromNode, String fromChannel,
String payloadType, byte[][] payload){
if( playloadType.equals(“BALL_COORD”)){
String coord = new String( payload[0] );
}
}
});
Air Hockey – 4. Exit Game
/**
* Stop Chord. We can call leaveChannel explicitly.
* mChord.leaveChannel (“com.samsung.multiairhockey.CHANNEL” );
*/
mChord.stop();
mChord.close();
Air Hockey – 4. Exit Game
/**
* Stop Chord. We can call leaveChannel explicitly.
* mChord.leaveChannel (“com.samsung.multiairhockey.CHANNEL” );
*/
mChord.stop();
mChord.close();
More…
Chord Unity Extension
ChordUnityApp
How to use interface APIs
ChordUnityInterface
Interface with
Samsung Chord and Unity3D
Samsung Chord SDK
ChordUnity3D Plugin Components
chordunity.unitypackage:
• chordUnityInterface.jar
• chord-v1.5.0.jar
• sdk-v1.0.0.jar
• libchord-v1.5.so
Download
 http://developer.samsung.com/samsung-mobile-sdk#chord
Testing with an emulator
Support
 http://developer.samsung.com/forum/en
Group Play SDK
Agenda










What is Group Play
Group Play Overview
Architecture
Inter Application communication
SDK Release & Setup
API Snapshot
API Usage Guidelines
Call Flows
Registering Group Play Apps
Use case
What is Group Play
 A content sharing service for multiple devices
• Share contents
-
Share video on each screen
Share music in channels
Share pictures, documents
and drawings in real-time
• Share experience
No of participants
Share games and apps for
real-time group play.
Dynamic presence update
about participants
Group Play Overview
 Features
–
–
–
–
Group Play makes a group using the Wi-Fi connection.
Group Play creates Internal Mobile AP network.
It gives contents sharing experience.
It is a hub for applications which are running on the Group Play Wi-Fi
group.
 SDK Objective
–
–
–
–
Creates a Wi-Fi network between devices via Group Play.
Displays a list of downloadable applications for Group Play.
Generates a list of downloaded applications for Group Play.
Displays Group Play status, such as the number of participants and the
application names.
Architecture
3rd party Apps
Group Play SDK
Group Play Core
Easy Connection
Mgmt.
Presence
Mgmt.
Mobile AP
Wi-Fi
Chord SDK
Chord Core
TCP/UDP
Platform
Multi-Player Games
Inter Application Communication
SDK Release & Setup
 Components
– Group Play SDK consists of the components listed below.
 Sdk-v1.0.0.jar
 GroupPlaySDK.jar
 Imported packages
– com.samsung.android.sdk
– com.samsung.android.sdk.groupplay
 Constraints
– Applications developed with Group Play SDK v1.0 require
Group Play v2.5 (or above, and Samsung Mobile SDK v1.0
to perform properly. It is also recommended to use Samsung Chord v1.5).
 Installing SDK and Creating Applications
– install Group Play SDK in an Eclipse environment:
– Add Sdk-v1.0.0.jar and GroupPlaySDK.jar files to the Eclipse libs folder.
API Snapshot
Group Play SDK is supported in Android 4.2.2 (Jelly Bean Plus MR1),and API Level 17 or higher.
API Category
Functional
Class
API
Description
sgp
initialize
sgpGroupPlay
runGroupPlay
Initialize group play . Return error if Group play SDK is not supported on de
vice
Launches Group Play and displays the start screen, for users to create or j
oin a group.
Initializes the Group Play service.
start
setParticipantInfo
getGroupPlayStatus
A user delivers join/exit related information to Group Play applications
STATUS_UNKNOWN
STATUS_NO_SESSION
STATUS_HAS_SESSION_AS_HOST
OnConnected
getVersionName
Callback when the service between the SDK and Group Play is disconnected
.
Returns the Group Play SDK version to “String” type value.
getVersionCode
Returns the Group Play SDK version to “int” type value.
OnDisConnected
Utility
sgp
STATUS_HAS_SESSION_AS_CLIENT
Callback when the service between the SDK and Group Play is connected.
API Usage Guidelines
public class App extends Application implements SgpConnectionStatusListener {
private static Sgp sgp = null;
private static SgpGroupPlay sdk = null;
private ChordManager mChordManager = null;
private IChordChannel channel =null;
@Override
public void onCreate() {
super.onCreate();
sgp = new Sgp();
try {
sgp.initialize(getApplicationContext());
} catch (SsdkUnsupportedException e) {
}
try {
new SgpGroupPlay(this).start(getApplicationContext());
} catch (IllegalArgumentException e) {
// Exception Handling
}
}
@Override
public void onConnected(SgpGroupPlaysdk) {
this.sdk = sdk;
if (sdk.hasSession()) {
sdk.setParticipantInfo(true);} // // Sends the joined status
mChordManager.start(interfaceType, mManagerListener);
mChordManager.joinChannel(CHORD_HELLO_TEST_CHANNEL, mChannelListener);
channel.sendData(fromNode, CHORD_SAMPLE_MESSAGE_TYPE, payload); }
}
API Usage Guidelines
case R.id.btn_run_groupplay:
if (App.getGroupPlaySdk() != null) {
if (App.getGroupPlaySdk().hasSession()) {
moveToNextActivity();
} else {
if (App.getGroupPlaySdk().runGroupPlay()) {
mMoveToNextActivity = true;
}
}
}
Sample Code to
break;
fetch Connection Info
Intent groupPlayIntent= getIntent();
String username = (String) groupPlayIntent. getStringExtra("DeviceName");
String networkInterface = (String) groupPlayIntent. getStringExtra("netIF");
netIF stands for Network Interface
wlan0 is for MobileAP
P2p-wlan0 is for Wi-Fi P2P
Call Flows - SDK initialization
: Sgp
: Application
: SgpGroupPlay
Group Play
<<create>>
1
2
3 : initialize()
4
<<create>>
5
6
7 : start()
<<connect to service>>
8
<<connection complete>>
9
10 : onConnected()
Call Flows - runGrouPlay
Call Group Play
Get result via
onActivityResult
Group Play SDK on Dev forum
Usecases…
Registering Group Play Apps


Register the application by following the procedure in “Seller Office
http://seller.samsungapps.com , register as a member.
<uses-permission android:name="android.permission.GET_TASKS" />
Manifest changes
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="GroupPlay" android:value="true" />
</application>

Successful registration and group play verification , application shall be shown in download tab .If installed
it will be shown in Games Option
Downloadable Apps
Installable Apps
Use case – Launch from Group Play App Menu
Multi Play
Use case – Enabling Multiplayer Gaming
 Dynamically launch Group Play while playing
Single User Play
Multi User Play
The runGroupPlay() API will launch GroupPlay.
After making a network, Group Play will resume
your application.
Use case - Notify user’s presence to Group Play
 Notify user’s presence to Group Play
The setParticipantInfo API will notify your status
to Group Play. And Group Play will show it.
Road Ahead
2013.3
2013.10
2014
Group Play 2.0
Group Play 2.5
Group Play 3.0
3rd party Dev
guide
Group Play SDK
Easy connection setup
Interaction with Group Play
Group Play SDK
+
Remote Group Play
Easy NFC tagging
Easy communication
Easy invitation
Get started
 Detailed information is available at
http://developer.samsung.com/group-play
Q&A
5. Q&A
Thank You!
License Notices
Except where noted, sample source code written by Samsung Electronics Co. Ltd and provided to you is licensed as described below.
Copyright © 2010-2013, Samsung Electronics Co. Ltd. All rights reserved except as otherwise explicitly indicated.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.

Neither the name of the Samsung Electronics Co. Ltd nor the names of its contributors may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Other source code displayed in this presentation may be offered under other licenses.
Apache 2.0
Copyright © 2010, Android Open Source Project. All rights reserved unless otherwise explicitly indicated.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Creative Commons 3.0 Attribution License
Portions of this presentation are reproduced from work created and shared by Google (http://code.google.com/policies.html) and used according to terms described in the
Creative Commons 3.0 Attribution License (http://creativecommons.org/licenses/by/3.0/).