Skip to main content

Android

This article guides you through setting up QQ as an identity provider, enabling your Android game to access Player Network authentication services.

Prerequisites

1. Set up the QQ app on QQ Connect
1. Create a QQ app
  1. Log in to QQ Connect.

  2. In the sidebar, click App Management.

  3. Click Create App.

    Image: Create an app

  4. Under Mobile App Information, enter the Android app information.

    • Android package name: Similar to com.intlgame.demo
    • Android signature: MD5 signature for Android.
      Delete the colon (:) in the MD5 signature and change all letters to lowercase. For example, for MD5=A1:B2..., enter a1b2....
    note

    Use the AppManage tool provided by QQ to obtain the Android signature, which is the MD5 value of the signature file.
    See Android FAQ for more information.

    When configuring multiple package names and signatures for Android on the QQ Connect console, separate them with a semicolon (;).

    Image: Mobile App Information

2. Get the app information
  1. Log in to QQ Connect.

  2. In the sidebar, click App Management.

  3. Click Edit in the Action column of the corresponding app.

    Image: Edit Apps

  4. On the app edit page, confirm the AppID and AppKey of the QQ app.

    Image: App Information

3. Apply for OpenAPI is_login permissions for QQ Connect

If the application has not been approved, even if QQ app login is successful, Player Network SDK will still return the error app has no privilege to use this api.
To apply for permissions, send an email according to the following template:

  • To: collinxu@tencent.com; ricesong@tencent.com
  • Cc: chuanhe@tencent.com; vissong@tencent.com; gavinyao@tencent.com; maytang@tencent.com; ricesong@tencent.com; (Product manager); (Technical manager); (Other project members)
  • Subject: [QQ Connect Application] is_login API -- Project XXX
  • Mail contents
    - QQ Connect appid:
    - App name:
    - Company name: (If not Tencent or a wholly owned subsidiary, attach an authorization letter regarding the relationship between the publisher and the developer.)
    - Entry point/scenario of the API: (Attach interactions if necessary.)
    - Timing of call:
    - Purpose of call:
    - Method to obtain accessToken/openkey:
    - Call volume (in minutes):
    - Person-in-charge: (WeCom names of product representative, developer representative.)

For more information, see is_login.

  1. Create an account for Player Network Console.
  2. Create a new project for your game, or join an existing one.
  3. Download the SDK.
  4. Integrate the SDK.
  5. Add QQ as an authentication method for your project on Player Network Console.

Step 1: Configure the SDK for QQ login

  1. Open the project's INTLConfig.ini:

    INTLConfig.ini
    [INTL environment]
    # WARNING: You should change this URL to the production environment when you release your game.
    INTL_URL = https://test.intlgame.com
    GAME_ID = {INTL_GAME_ID}
    SDK_KEY = {INTL_SDK_KEY}
    [INTL Log]
    LOG_LEVEL = 1
    LOG_CONSOLE_OUTPUT_ENABLE = 1
    LOG_FILE_OUTPUT_ENABLE = 1
    LOG_ENCRYPT_ENABLE = 0
    LOG_COMPRESS_ENABLE = 0

    [Android LifeCycle]
    LIFECYCLE = QQ
    [QQ]
    QQ_APP_ID = {INTL_QQ_APP_ID}
    • Set the SDK backend environment to INTL_URL = https://test.intlgame.com.
    • Replace {INTL_GAME_ID} and {INTL_SDK_KEY} with the GAME_ID and SDK_KEY assigned by Player Network Console.
    • Set LOG_LEVEL = 1, LOG_CONSOLE_OUTPUT_ENABLE = 1, LOG_FILE_OUTPUT_ENABLE = 1, LOG_ENCRYPT_ENABLE = 0, and LOG_COMPRESS_ENABLE = 0 to output console logs and log files without encrypting or compressing the output.
    • Add QQ to LIFECYCLE. For more information, see SDK Environment.
    • Replace {INTL_QQ_APP_ID} with the AppID assigned by QQ.
  2. Define manifestPlaceholders in your gradle file by replacing {INTL_QQ_APP_ID} as the QQ AppID.

    mainTemplate.gradle
    android {
    defaultConfig {
    manifestPlaceholders = ["QQ_APPID":"{INTL_QQ_APP_ID}"]
    }
    }
  3. Declare the permissions and activities in the AndroidManifest.xml file according to the following code.

    AndroidManifest.xml
    <manifest ... >
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    ...
    <application ... >
    <activity android:name="com.example.myapp.MainActivity" ... >
    ...
    </activity>
    ...
    <activity
    android:name="com.tencent.connect.common.AssistActivity"
    android:configChanges="orientation|keyboardHidden"
    android:screenOrientation="behind"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    <activity
    android:name="com.tencent.tauth.AuthActivity"
    android:launchMode="singleTask"
    android:noHistory="true" >
    <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="tencent{INTL_QQ_APP_ID}" />
    </intent-filter>
    </activity>
    ...
    </application>
    ...
    </manifest>

    Replace {INTL_QQ_APP_ID} with the AppID assigned by QQ.

Step 2: Add QQ login

When calling INTLAPI.Login, pass the permission type. It is recommended to pass "all", which indicates all the permissions on the platform that has been applied for. When no permission is passed, Android uses the get_simple_userinfo permission by default.

PermissionsDescription
get_simple_userinfoQQ login permission(Obtain QQ user information on the mobile end)
  1. Add an observer to handle authentication callbacks.

    // Add callbacks
    public void AddAuthObserver()
    {
    INTLAPI.AddAuthResultObserver(OnAuthResultEvent);
    }

    // Remove callbacks
    public void RemoveAuthObserver()
    {
    INTLAPI.RemoveAuthResultObserver(OnAuthResultEvent);
    }

    // Process the INTLAuthResult callback
    public void OnAuthResultEvent(INTLAuthResult ret)
    {
    Debug.Log($"MethodID: {ret.MethodId}");

    string methodTag = "";
    if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_LOGIN)
    {
    methodTag = "Login";
    }
    else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_BIND)
    {
    methodTag = "Bind";
    }
    else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_AUTOLOGIN)
    {
    methodTag = "AutoLogin";
    }
    else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_QUERY_USER_INFO)
    {
    methodTag = "QueryUserInfo";
    }
    else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_GET_AUTH_RESULT)
    {
    methodTag = "GetAuthResult";
    }
    }
  2. Call the AutoLogin method.

    INTLAPI.AutoLogin();
  3. Call the Login method to ask for user input if auto-login fails.

    INTLAPI.Login(INTLChannel.QQ, "all", "");
  4. Sync client authentication state with the game's backend and wait for the final authentication result.

Step 3: Test the login function

Search for the keyword "AuthResult" in the Player Network SDK logs to verify if the correct channel name and OpenID are returned. If they are, it indicates a successful configuration and the login function has been added successfully.