android-usage-guide

*We assure you that we do not spam. You may receive occasional emails from us.
 You can always unsubscribe.
Android

Android Getting Started

WarpClient provides an interface for applications to interact with the cloud services. It allows client side applications to connect, subscribe and manage server side rooms, lobbies and users. The APIs are developed to be used asynchronously, which means you simply add the corresponding request listeners to the WarpClient instance to receive responses and updates. This page describes to how to set up your connection with the cloud server and introduces API usage.

Complete API Reference

In order to use the various functions available, you will have to initialize and connect the instance of WarpClient. WarpClient is initialized by passing the apiKey and secretKey which you received after creating an app from AppHq (App42 management console).

WarpClient.initialize("Your API Key", "Your Secret Key"); 

After initialization, it is recommended that you implement and add a request listeners which will be called by WarpClient with the result of the requests. WarpClient comprises different listeners for different type of requests namely

  • Connection Request Listener
  • Lobby Request Listener
  • Zone Request Listener
  • Room Request Listener
  • Notification Listener
WarpClient myGame = WarpClient.getInstance();  
myGame.addConnectionRequestListener(new MyConnectionListener());  
myGame.connectWithUserName("Jonathan");  

The connection request listener callback will be invoked once the connection with the Warp server has been established with the given username. If this is successful, you can go ahead and call the room/lobby APIs of your app zone. Note that two users can not be connected to the online application simultaneously. Here is a simple implementation of a request listener.

public class MyConnectionListener implements ConnectionRequestListener{
    @Override
    public void onConnectDone(ConnectEvent event) {
        if(event.getResult() == WarpResponseResultCode.SUCCESS){            
			System.out.println("yipee I have connected");
        }
    }
    @Override
    public void onDisconnectDone(ConnectEvent event) {
        System.out.println("On Disconnected invoked");
    } 
@Override
    public void onInitUDPDone(byte paramByte) {
        // TODO Auto-generated method stub        
    }   
}
addZoneRequestListener : Add your listener object on which callbacks will be invoked when a response from the server is received for Zone level requests like create/deleteRoom, User requests etc.
public void addZoneRequestListener(ZoneRequestListener listener)

addRoomRequestListener : add your listener object on which callbacks will be invoked when a response from the server is received for Room requests like join/leaveRoom, subscribe/unsubscribeRoom and getLiveRoomInfo

public void addRoomRequestListener(RoomRequestListener listener)

addLobbyRequestListener : add your listener object on which callbacks will be invoked when a response from the server is received for Lobby requests like join/leaveLobby, subscribe/unsubscribeLobby and getLiveLobbyInfo.

public void addLobbyRequestListener(LobbyRequestListener listener)

addNotificationRequestListener : add your listener object on which callbacks will be invoked when a notification is received from the server for any resource that has been subscribed to.

public void addNotificationListener(NotifyListener listener)

Result Codes : These can be retrieved when an event callback is invoked from the event instance.

byte SUCCESS = 0;    
byte AUTH_ERROR = 1;    
byte RESOURCE_NOT_FOUND = 2;    
byte RESOURCE_MOVED = 3;     
byte BAD_REQUEST = 4;
byte CONNECTION_ERR = 5;
byte UNKNOWN_ERROR = 6;
byte RESULT_SIZE_ERROR = 7;

Appwarp also allows you to set custom data for users and rooms through the methods setCustomUserData() and setCustomRoomData(). To retrieve the custom data and other information WarpClient comprises getLiveUserInfo() and getLiveRoomInfo() methods.