Getting Started

Last updated: 2020-04-01 16:48:46

    This document describes how to get started with the GME APIs for Android.

    This document only describes the most important APIs to help you get started with GME. For more information on APIs, please see the API documentation.

    Important API Description
    Init Initializes GME
    Poll Triggers event callback
    EnterRoom Enters room
    EnableMic Enables mic
    EnableSpeaker Enables speaker
    • Configure your project before using GME; otherwise, the SDK will not take effect.
    • After a GME API is called successfully, QAVError.OK will be returned with the value being 0.
    • GME APIs should be called in the same thread.
    • The Poll API should be called periodically for GME to trigger event callbacks.
    • For GME callback messages, please see the callback message list.
    • Operation on devices should be performed after successful room entry.
    • For detailed error codes, please see Error Codes.

    Directions for Quick Access

    1. Get a singleton

    To use the voice feature, get the ITMGContext object first.

    Function prototype

    public static ITMGContext GetInstance(Context context)
    Parameter Type Description
    context Context Application context object

    Sample code

    import com.tencent.TMG.ITMGContext; 
    TMGContext.getInstance(this);

    2. Initialize the SDK

    For more information on how to get parameters, please see Access Guide.
    This API requires the AppID from the Tencent Cloud Console and the openID as parameters. The openID uniquely identifies a user with the rules stipulated by the application developer and must be unique in the application (currently, only INT64 is supported).

    The SDK must be initialized so that a room can be entered.

    Function prototype

    ITMGContext public int Init(String sdkAppId, String openId)
    Parameter Type Description
    sdkAppId String AppId from the Tencent Cloud Console.
    openID String OpenID can only be in Int64 type (converted to string) with a value greater than 10,000, which is used to identify the user.

    Sample code

    ITMGContext.GetInstance(this).Init(sdkAppId, openID);

    3. Trigger event callback

    The Poll API in updated should be called periodically for GME to trigger event callbacks; otherwise, the entire SDK service will not work properly.

    Function prototype

    ITMGContext int Poll()

    Sample code

    ITMGContext.GetInstance(this).Poll();

    4. Authenticate

    Generate AuthBuffer for encryption and authentication of relevant features. For release in the production environment, please use the backend deployment key as detailed in Authentication Key.
    To get authentication for voice messaging and speech-to-text, the room ID parameter must be set to null.

    Function prototype

    AuthBuffer public native byte[] genAuthBuffer(int sdkAppId, String roomId, String identifier, String key)
    Parameter Type Description
    appId int AppId from the Tencent Cloud Console.
    roomId string Room ID, which can contain up to 127 characters (for voice messaging and speech-to-text feature, enter null).
    openId string User ID, which is the same as openID during initialization.
    key string Permission key from the Tencent Cloud Console.

    Sample code

    import com.tencent.av.sig.AuthBuffer;// Header file
    byte[] authBuffer=AuthBuffer.getInstance().genAuthBuffer(Integer.parseInt(sdkAppId), strRoomID,identifier, key);

    5. Enter a room

    When a client enters a room with the generated authentication information, the ITMG_MAIN_EVENT_TYPE_ENTER_ROOM message will be received as a callback. Mic and speaker are not enabled by default after room entry. The returned value of AV_OK indicates a success.

    Function prototype

    ITMGContext public abstract int EnterRoom(String roomId, int roomType, byte[] authBuffer)
    Parameter Type Description
    roomId String Room ID, which can contain up to 127 characters
    roomType int Room audio type
    authBuffer byte[] Authentication code

    For more information on how to choose a room audio type, please see Sound Quality Selection.

    Sample code

    ITMGContext.GetInstance(this).EnterRoom(roomId,roomType, authBuffer);    

    6. Receive callback for room entry

    After the client enters the room, the message ITMG_MAIN_EVENT_TYPE_ENTER_ROOM will be sent and identified in the OnEvent function.
    Sample code for setting the callback:

    private ITMGContext.ITMGDelegate itmgDelegate = null;
    itmgDelegate= new ITMGContext.ITMGDelegate() {
                @Override
                 public void OnEvent(ITMGContext.ITMG_MAIN_EVENT_TYPE type, Intent data) {
                    }
            };

    Sample code for processing the callback:

    Sample code

    public void OnEvent(ITMGContext.ITMG_MAIN_EVENT_TYPE type, Intent data) {
        if (ITMGContext.ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_ENTER_ROOM == type)
            {
                    // Receive the event of successful room entry
            }
        }

    7. Enable/Disable the mic

    This API is used to enable/disable the mic. Mic and speaker are not enabled by default after room entry.

    Function prototype

    ITMGContext public void EnableMic(boolean isEnabled)
    Parameter Type Description
    isEnabled boolean To enable the mic, set this parameter to true; otherwise, set it to false.

    Sample code

    ITMGContext.GetInstance(this).GetAudioCtrl().EnableMic(true);

    8. Enable/Disable the speaker

    This API is used to enable/disable the speaker.

    Function prototype

    ITMGContext public void EnableSpeaker(boolean isEnabled)
    Parameter Type Description
    isEnabled boolean To disable the speaker, set this parameter to false; otherwise, set it to true.

    Sample code

    ITMGContext.GetInstance(this).GetAudioCtrl().EnableSpeaker(true);

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help