tencent cloud

Feedback

Android

Last updated: 2018-09-28 17:02:27
The documentation is not available now.

    This document describes how to integrate iLiveSDK to your client using the repository and how to log in to Tencent Cloud.

    Downloading Source Code

    You can download the complete demo code used in this document.
    Download Demo Code

    Prerequisites

    You must have activated the service and created an application at the TRTC official website.

    Concepts

    Obtaining userSig

    Each user at Client is provided with a userSig. It is valid for three months upon generation. If the userSig expires, the user cannot log in to TRTC and will receive the error code 8051. At this time, the user should generate a new userSig to log in to TRTC.

        /** Ticket expired (Need to update ticket userSig) */
        public static final int ERR_EXPIRE              = 8051;
    

    Note: For more information on how to obtain a userSig, see User Authentication.. During debugging, you can directly use the development tools in the console to generate a userSig.

    Adding a Dependency (Integrating SDK)

    Modify the build.gradle file and add the dependency of iLiveSDK in "dependencies":

    compile 'com.tencent.ilivesdk:ilivesdk:latest.release'  //latest.release refers to the latest iLiveSDK version number
    

    Initializing iLiveSDK

    Add DemoApp.java and inherit Application:

    public class DemoApp extends Application {
        @Override
        public void onCreate() {
            super.onCreate();
    
            //Check whether initialization is only performed in the main thread
            if (MsfSdkUtils.isMainProcess(this)) {
                //Initialize iLiveSDK
                ILiveSDK.getInstance().initSdk(this, Constants.SDKAPPID, Constants.ACCOUNTTYPE);
                //Initialize iLiveSDK room management module
                ILiveRoomManager.getInstance().init(new ILiveRoomConfig());
            }
        }
    }
    

    In the application of AndroidManifest.xml, declare:

    <application
            ......
            android:name=".DemoApp">
            ......
        </application>
    

    Creating the Login Module

    Create a communication API for the login module and Activity:

    public interface ILoginView {
        //Login successful
        void onLoginSDKSuccess();
        //Login failed
        void onLoginSDKFailed(String module, int errCode, String errMsg);
    }
    

    At the same time, create a LoginHelper.java for login:

    public class LoginHelper {
        private ILoginView loginView;
    
        public LoginHelper(ILoginView view){
            loginView = view;
        }
    
        public void loginSDK(String userId, String userSig){
            ILiveLoginManager.getInstance().iLiveLogin(userId, userSig, new ILiveCallBack() {
                @Override
                public void onSuccess(Object data) {
                    loginView.onLoginSuccess();
                }
    
                @Override
                public void onError(String module, int errCode, String errMsg) {
                    loginView.onLoginFailed(module, errCode, errMsg);
                }
            });
        }
    }
    

    Listening for Account Status

    The Listening feature of the application is used to listen for forced logout due to repeated login or expired userSig.
    You can create an observer to listen globally:

    /**
     * Status observer
     */
    public class StatusObservable implements ILiveLoginManager.TILVBStatusListener {
    
        //Message listening linked list
        private LinkedList<ILiveLoginManager.TILVBStatusListener> listObservers = new LinkedList<>();
        //Handle
        private static StatusObservable instance;
    
    
        public static StatusObservable getInstance(){
            if (null == instance){
                synchronized (StatusObservable.class){
                    if (null == instance){
                        instance = new StatusObservable();
                    }
                }
            }
            return instance;
        }
    
    
        //Add an observer
        public void addObserver(ILiveLoginManager.TILVBStatusListener listener){
            if (!listObservers.contains(listener)){
                listObservers.add(listener);
            }
        }
    
        //Remove an observer
        public void deleteObserver(ILiveLoginManager.TILVBStatusListener listener){
            listObservers.remove(listener);
        }
    
        //Obtain the number of observers
        public int getObserverCount(){
            return listObservers.size();
        }
    
        @Override
        public void onForceOffline(int error, String message) {
            //Copy the linked list
            LinkedList<ILiveLoginManager.TILVBStatusListener> tmpList = new LinkedList<>(listObservers);
            for (ILiveLoginManager.TILVBStatusListener listener : tmpList){
                listener.onForceOffline(error, message);
            }
        }
    }
    

    After successful login, call the API to set listening:

    ILiveLoginManager.getInstance().setUserStatusListener(StatusObservable.getInstance());
    

    In this way, you will know you are forced logout after receiving the OnForceOffline event.

    UI Development

    A separate login page is required to enter the user name and password at the client. Such basic knowledge of Android development will not be discussed here.

    Log in to the onCreated event in the application, and then you can create the module defined above:

    loginHelper = new LoginHelper(this);
    

    Click the login event to obtain the userId and userSig entered by the user. Call the login API of loginHelper to log in:

    loginHelper.loginSDK(userId, userSig);
    

    FAQ

    • Failed to download aar

      Error:Could not resolve all files for configuration ':app:debugCompileClasspath'.
      > Could not resolve com.tencent.ilivesdk:ilivesdk:1.8.3.
      Required by:
      project :app
      > Could not resolve com.tencent.ilivesdk:ilivesdk:1.8.3.
      > Could not get resource 'https://jcenter.bintray.com/com/tencent/ilivesdk/ilivesdk/1.8.3/ilivesdk-1.8.3.pom'.
      > Could not GET 'https://jcenter.bintray.com/com/tencent/ilivesdk/ilivesdk/1.8.3/ilivesdk-1.8.3.pom'.
      > Connect to jcenter.bintray.com:443 [jcenter.bintray.com/75.126.118.188] failed: Connection timed out: connect
      

      Check the network first. Then, check whether the jcenter website is accessible by clicking on the above link. If a proxy is required, check if it is configured in gradle.properties.

    • Log in to IMSDK, a module that does not return any error. Error code: 70009. Error description: tls_checksignature failed decrypt sig failed failed iRet:-2 sdkappid:14000xxxxx,acctype:xxxx,identifier:guest sig:E9vB6Ocs42J8A5lZW6s

    This may be caused by mismatch between the userSig and ID. Check whether the key for generating the userSig matches the sdkAppId used in initialization.

    Email

    If you have any questions, send us an email to trtcfb@qq.com.

    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support