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) {
Wednesday, April 20, 2016
Multiple Ways of Programming for Android
These seem to be more than one way to program for the Android devices.
The first and the most common way is by using the Software Development Kit (SDK) using Java Syntax. This is what I have been talking about in all the earlier posts and tutorials.
The other 3 interesting ways, I believe, are:
2. Native Development Kit using C / C ++. This I am sure many are aware of and would be using to some extent. This is a little more closer to the OS, not running on top of the virtual Machine.
3. RenderScript using C99 - used to write faster graphics code like the Google Books page turn animation etc.
4. Android Scripting Layer using Python etc.
Interesting options, right?
Read More..
The first and the most common way is by using the Software Development Kit (SDK) using Java Syntax. This is what I have been talking about in all the earlier posts and tutorials.
The other 3 interesting ways, I believe, are:
2. Native Development Kit using C / C ++. This I am sure many are aware of and would be using to some extent. This is a little more closer to the OS, not running on top of the virtual Machine.
3. RenderScript using C99 - used to write faster graphics code like the Google Books page turn animation etc.
4. Android Scripting Layer using Python etc.
Interesting options, right?