API reference and external event listeners

更新时间:
复制 MD 格式

This document describes the API methods and external event listeners for the Android Alibaba Cloud Game Platform as a Service (PaaS) SDK.

API methods and descriptions

API

Description

init

Initializes the SDK. Pass the `accessKey` and `accessSecret` fields for authentication. Returns `101030` if authentication fails.

prepare

Pass game-related parameters to start resource scheduling before the game launches.

stopPreparing

Stops queuing.

start

Pass the game container to the SDK to start the game. Call this method from the game page.

stop

Call this method when closing the game page to notify the game server to destroy the instance.

pause

Call this method to pause the game when the app moves to the background.

resume

Call this method to resume the game when the app returns to the foreground.

customGamepadEvent

customKeyboardEvent

customMouseEvent

Custom gamepad event.

Custom keyboard event.

Custom mouse event.

setDefaultGamepadIndex

defaultGenericMotionEvent

defaultKeyDown

defaultKeyUp

defaultTouchEvent

Set the index for the SDK's built-in gamepad.

Use the SDK to handle physical gamepad, keyboard, and mouse events.

Use the SDK to handle physical gamepad, keyboard, and mouse events.

Use the SDK to handle physical gamepad, keyboard, and mouse events.

Use the SDK to handle touch events.

sendTextToGame

Send text or messages to the game.

setHidConfig

Set the enabled status of a configuration item. `true` indicates enabled. For more information about configuration items, see CGHid.

getHidConfig

Get the enabled status of a configuration item. `true` indicates enabled. For more information about configuration items, see CGHid.

requestRegionList

Request the server nodes that the current game can connect to.

getCurrentRegion

On the game page, get the server node that the current game is connected to.

getVersion

Get the SDK version number.

loadPlugin

Load a remote game plugin.

getGameSession

Get the current game session for online play.

External event listeners and examples

eventType

eventCode

eventMessage

10

101030

101040

101099

102010

102030

Tenant authentication error.

Service request timeout.

Abnormal service request.

Failed to attach the device for the persistent connection.

Failed to attach the user.

20

201010

The game page Activity can be started.

30

301010

301020

301030

The remote game plugin package was not loaded successfully.

The remote game plugin package was loaded successfully.

Failed to load the remote game plugin package.

40

401010

401020

402010

402020

JSON data. Data returned for the node list: `RegionObj`.

JSON data. Data returned for the queuing API, including queuing, canceling queue, and queue completion: `CGSlotObj`.

JSON data. Fields related to the trial duration.

JSON data. In-game trial notification.

50

501010

501020

501030

501040

502010

502020

502030

502040

502050

502060

503010

503020

503030

503040

503050

503060

503070

504010

504020

504030

505010

509010

509099

Exiting the game. Archiving data and clearing resources.

Scheduling failed. The client decides to reschedule.

Game startup failed.

The online session has expired.

Abnormal game data.

The game is not online.

The game does not belong to the tenant.

The game does not belong to the project.

The concurrency for the tenant project is 0.

The tenant's game server is under maintenance.

Tenant error.

The tenant's AccessKey is empty.

The tenant project is empty.

The user ID is empty.

The same user is clicking frequently.

No game instances are available.

The game is not authorized for the user.

System error.

Service unavailable.

Parameter parsing error.

The trial has ended.

Scheduling error: The IP address or port is empty.

Other unknown scheduling errors.

60

601010

601020

601030

601040

609010

Failed to archive data when exiting the game last time.

Unknown error when exiting the game last time.

Game container initialization failed.

Game container initialization timed out.

Container initialization error: The IP address or port is empty.

70

701010

701020

The game stopped because the trial ended.

The game stopped due to a long period of inactivity.

200

2001011

2001012

2001013

2001020

2001030

2001040

2001041

2001050

2001060

2001070

2001071

2001080

2001090

The player clicked Exit within the game.

The player was removed from the game due to a long period of inactivity.

The player was removed from the game because the account was used to log on from another device.

User authentication failed when connecting to the server.

The game failed to start because the app moved to the background during startup.

Failed to connect to the server.

The server connection was disconnected.

The server stopped the game.

The game was disconnected because the startup time exceeded the loading time limit.

Game frozen due to a server runtime environment issue.

A service interruption occurred because the game exited unexpectedly.

The game server that you are trying to connect to is aborting.

The user was removed from the game.

220

2201010

Network disconnected. Attempting to reconnect to the game.

230

2301010

The game reconnected successfully.

250

2501010

The game failed to reconnect.

270

2701010

2701011

2701012

2701040

Starting the game instance.

The server connected successfully.

Startup authentication was successful.

The game screen is ready. Startup is complete.

280

2801010

2801020

2801030

The message value is the bitrate.

The message value is the frame rate.

The message value is the network latency.

Example: How to listen for SDK notifications externally

private BroadcastReceiver mLocalBroadcastReceiver = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(CGGameConstants.ACTION_ACG_GAMEEVENT)) { 
            Bundle bundle = intent.getExtras(); 
            int eventType = bundle.getInt(CGGameConstants.EVENT_TYPE); 
            String eventCode = bundle.getString(CGGameConstants.EVENT_CODE); 
            String eventMessage = bundle.getString(CGGameConstants.EVENT_MESSAGE); 
            //todo your code 
        }
     }
 }

CGHid

Contains information about the gamepad mode.

public enum CGHid

Constants

Name (including declared parameters)

Description

HID_VIRTUAL("virtualGamePadEnabled",1)

Virtual gamepad mode.

HID_TOUCH("touchEventEnabled",2)

Touch screen mode.

HID_PHYSICAL("physicalGamePadEnabled",3)

Physical gamepad mode.

HID_MOUSE("mouseEnable",4)

Mouse mode.

HID_KEYBOARD("keyboardEnable",5)

Keyboard mode.