Please Wait

Loading..

Android SDK 1.0.0

Create amazing realtime applications easily with Yalgaar Android SDK

Android SDK

1 Connect To Yalgaar

Requirement:

Android device with version 4.0 or above.

Download package and include library in your code, Create instance of Yalgaar client with context of application.

YalgaarApiClient objYalgaarClient = new YalgaarApiClient.Builder(context).build();

To connect to a Yalgaar client, use following method, it must have valid Client Key.

connect(String Clientkey, boolean IsSecure, ConnectionCallback callback);
connect(String Clientkey, boolean IsSecure,String UUID, ConnectionCallback callback);
connect(String Clientkey, boolean IsSecure, String AESSecretKey, AESType type,ConnectionCallback callback );
connect(String Clientkey, boolean IsSecure,String AESSecretKey, AESType type, String UUID, ConnectionCallback callback);

Parameter:

  • Clientkey
    • Description: Yalgaar provided authentic client key for project.
    • DataType: String
  • IsSecure
    • Description: Specified connection is establish with SSL or not.
    • DataType: boolean
  • AESSecretKey
    • Description: Secret key use for encrypt/decrypt message.
    • DataType: String
  • AESType
    • Description: Type of AES algorithm use for encrypt/decrypt message. Support AES_128, AES_192, AES_256
    • DataType: AESType
  • UUID
    • Description: Any unique user name for user to enable presence feature for client.
    • DataType: String
  • ConnectionCallback
    • Description: ConnectionCallback or null. There are three types of callbacks.
      • connectSuccessfullyCallback: called when successfully connected to server.
      • connectionErrorCallback: called when system error occurred during connection.
      • connectionDisconnectCallback: called when connection disconnect with server.
    • DataType: ConnectionCallback


2 Publish Message

To publish message, use following method.

publish(String Channel, String Message, PublishMessageCallback PublishCallback);

Parameter:

  • Channel
    • Description: Channels name on which message will be published. Channel name is CASE SENSITIVE.
    • DataType: String
  • Message
    • Description: Data to be send.
    • DataType: String
  • PublishMessageCallback
    • Publish Callback or null. There are two types of callbacks.
      • successCallback: called on successfully send message.
      • errorCallback: called on error occurred during publish message.
    • DataType: PublishMessageCallback


3 Subscribe Message

To subscribe message, use following method.

subscribe(String channel, SubscribeCallback subscriptionCallback, PresenceCallback presenceCallback);
subscribe(ArrayList channels, SubscribeCallback subscriptionCallback, PresenceCallback presenceCallback);

Parameter:

  • Channel(s)
    • Description: Single channel name or arraylist of channels name on which message will be published. Channel name is CASE SENSITIVE.
    • DataType: String (for multiple channels use arrayList).
  • SubscribeCallback
    • Description: Subscription Callback or null. There are three types of subscription callbacks. successSubCallback, messageRecieveSubCallback, and errorSubCallback.
      • successSubCallback: called on successfully subscription of channel(s).
      • messageRecieveSubCallback: called on any data arrived in channel(s).Data will be available in form of string.
      • errorSubCallback: called on system error occurred during subscription.
    • DataType: SubscribeCallback
  • PresenceCallback
    • Description: Use for get presence information from yalgaar server. its work when you create Yalgaar client with UUID.
    • presenceMessageReceiveCallback: called on any presence message arrive from server.
    • DataType: PresenceCallback


4 Unsubscribe Message

To unsubscribe message, use following method.

unSubscribe(String Channel, UnSubscribeCallback unSubscribeCallback);
unSubscribe(String ChannelList, UnSubscribeCallback unSubscribeCallback);
  • Channel(s)
    • Description: Single channel name or arraylist of channels to be unsubscribe. Channel name is CASE SENSITIVE.
    • DataType: String or arrayList for multiple channels.
  • UnSubscribeCallback
    • Description: Subscription Callback or null. There are two types of subscription callbacks. successUnSubscribeCallback, and errorUnSubCallback.
      • successUnSubscribeCallback: called on successfully unsubscribe channel.
      • errorUnSubCallback: called on system error occurred during unsubscribe.
    • DataType: UnSubscribeCallback


5 Get User List

To get list of all user subscribe with specified channel name, use following method.

getUUIDList(String Channel, DataCallback callback);

Parameter:

  • Channel
    • Description: Name of valid channel name. Channel name is CASE SENSITIVE.
    • DataType: String
  • DataCallback
    • Description: DataCallback or null. Call on response from server. If there is not matching channel name then response will be empty arrayList.
    • DataType: DataCallback


6 Get Channel List

To get list of all channels subscribed by specified user, use following method.

getChannelList(String UUID, DataCallback callback);

Parameter:

  • UUID
    • Description: Valid UUID. UUID is CASE SENSITIVE.
    • DataType: String
  • DataCallback
    • Description: Call on response from server. If there is no user with specified UUID then response will be empty arrayList.
    • DataType: DataCallback


7 History Message

To get message history from specified channel name, use following method.

getHistory(String Channel, int MessageCount, HistoryCallback callback);

Parameter:

  • Channel Name
    • Description: Name of valid channel name. Channel name is CASE SENSITIVE.
    • DataType: String
  • MessageCount
    • Description: How many messages that you want to fetch. Maximum 100 messages allow at a time.
    • DataType: int
  • HistoryCallback
    • Description: HistoryCallback or null. Call on response from server. If there is not matching channel name then response will be empty arrayList. Otherwise return arrayList of “Message” object.
    • HistoryMessage: Contains two methods.
      • getMessage(): returns String message.
      • GetTimeStamp() : returns message time in milliseconds.
    • DataType: HistoryCallback


8 Disconnect

To disconnect connection with YalgaarClient, use following method.

disConnect();



Note:

You must have follow below step to successfully use yalgaar android SDK.

Step 1:

Add “yalgaar.aar” file in libs folder of application module.

Step 2:

Add following code in build.gradle file of application module.

android {
    repositories{
        flatDir{
            dirs 'libs'
        }
    }
}
dependencies {
    compile(name:'yalgaar', ext:'aar')
}

Step 3:

You can publish/subscribe message like below.

import com.sls.yalgaar_api;

public class YalgaarNet extends Activity {
    YalgaarApiClient yalgaarApiClient;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yalgaar_net_layout);
        yalgaarApiClient = new YalgaarApiClient.Builder(this).build();
    }
    private void connect(String clientKey,boolean isSecure) throws ArgumentException,
    ConnectFailureException
    {
        yalgaarApiClient.connect(clientKey, isSecure, connectionCallback);
    }
    private ConnectionCallback connectionCallback = new ConnectionCallback()
    {
        @Override
        public void connectSuccessfullyCallback(String message) {
            Log.i("Yalgaar",message);
        }
        @Override
        public void connectionErrorCallback(String message) {
            Log.e("Yalgaar",message);
        }
        @Override
        public void connectionDisconnectCallback(String message) {
            Log.w("Yalgaar",message);
        }
    };
    private void publishMessage() throws ArgumentException, ConnectFailureException
    {
        yalgaarApiClient.publish("YourChannel", "This is Yalgaar Android SDK Example.", null);
    }
    private void subscribeMessage() throws ArgumentException, ConnectFailureException
    {
        yalgaarApiClient.subscribe("YourChannel",subscribeCallback, null);
    }
    private SubscribeCallback subscribeCallback = new SubscribeCallback()
    {
        @Override
        public void successSubCallback(ArrayList<string> channels, String message) {
            Log.i("Yalgaar",message);
        }
        @Override
        public void messageReceiveSubCallback(ArrayList<string> channel, String message) {
            Log.i("Yalgaar",message);
        }
    };
    private void disConnect(){
        yalgaarApiClient.disConnect();
    }
}