However, by the time I developed the 1stapp, it still seemed like a lot of code. Of course this kind of an app is meant to do a lot more than just say Hello World. Its power is best utilized in developing games, I would say.
Like the poker game that is available in the Samsung Android developer documentation.
So, What are the steps to start with?
Step 1: You first need to create a channel. I do this when I initialize my service. I have written a service that gets an instance of the ChordManager.
public voidinitialize(IChordServiceListener csListener) {
if (mChord != null) {
return;
}
mChord = ChordManager.getInstance(this);
mListener = csListener;
mChord.setTempDirectory(chordFilePath);
mChord.setHandleEventLooper(getMainLooper());
}
Note that I have got an ChordManager here and associated a temporary file path and a the apps main looper.
Step 2: Next, You would want a way to join the channel So, let us implement the joinChannel() method and leaveChannel() method as its complement.
This is after the ChordManager is up and running.
public IChordChannel joinChannel(String channelName) {
if (channelName == null || channelName.equals("")) {
mPrivateChannelName = MYCHANNEL;
} else {
mPrivateChannelName = channelName;
}
IChordChannel channelInst = mChord.joinChannel(mPrivateChannelName, mChannelListener);
if (null == channelInst) {
return null;
}
return channelInst;
}
This seems straight forward. MYCHANNEL is a constant declared earlier as public static String MYCHANNEL = "com.sai.CHANNELONE";
If the caller does not pass a channel name, the default one declared would be used.
While joining a channel, we need to pass the Channel name and also an associated listener that is of the type IChordChannelListener.
So next step would be implement this listener.
Note the leave channel code would be like this:
public voidleaveChannel() {
mChord.leaveChannel(mPrivateChannelName);
mPrivateChannelName = "";
}
Step 3: Implement the IChordChannelListener.
All the 9 methods of this have to be implemented. These are the methods that would be called back when a file is sent or data is received etc. And the actual implementation for this would be in the Activity that is invoking the ChordManager service.
Here, based on the example from Samsung, I have also implemented these methods mainly as a way of calling a listener that is implemented by the activity invoking it.
@Override
public void onDataReceived(String arg0, String arg1, String arg2,
byte[][] arg3) {
0 comments:
Post a Comment