">mixi Developer Center (mDC)

mixi Connect

mixi Connect (English) » mixi Graph API » mixi API SDK for Android™ » Initialization and authorization process

Initialization and authorization process

This section describes how to write code when developing applications that use the mixi API SDK for Android™.

Describing an activity

The following shows a sample code for a main activity in an application that uses the mixi API SDK for Android™.
At a minimum, you must include this code for the functions of the SDK to work properly.

package com.example.foo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import jp.mixi.android.sdk.*;

public class TestActivity extends Activity {
    MixiContainer mContainer;

    public void onCreate(Bundle savedInstanceState) {

        Config config = new Config();
        config.clientId = "YOUR_CONSUMER_KEY";
        config.selector = Config.GRAPH_API;

        mContainer = MixiContainerFactory.getContainer(config);

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mContainer.authorizeCallback(requestCode, resultCode, data);

    public void onDestroy() {

(1)Start process (e.g., onCreate)

To use the SDK, you must call the init (Activity activity) method of the MixiContainer instance. You can use MixiContainerFactory.getContainer(Config config) to create the MixiContainer instance. Select the following settings for Config.

Type Field name Description
String clientId Select the consumer key created during application registration
Int selector Select "Config.GRAPH_API"

(2) End process (e.g., onDestroy)

Execute MixiContainer#close() to properly end the process.

(3) Obtaining the authorization result (onActivityResult)

Call authorizeCallback() in onActivityResult to obtain the result from the authorization dialog.

Calling the authentication authorization dialog

To use the API for mixi apps, a user must be authorized prior to use. The authorize method displays the authorization screen for the process.

void MixiContainer#authorize(Activity activity, String[] permissions, int activityCode,
    CallbackListener listener)
activity Specify the source activity (e.g., FooActivity.this).
permissions Specify the scope required to use the API (mixi_apps).Please refer to the appropriate API document for instructions (such as "r_profile", "w_photo")
activityCode Code value for evaluating the intent destination
listener Callback class that is called after the authorization process is completed.

Calling this method returns the following screen.

The sample code is as follows.

mContainer.authorize(TestActivity.this, new String[] {"r_profile","w_voice"}, AUTHORIZE_REQUEST_CODE,
    new CallbackListener() {
        public void onComplete(Bundle values) {
            // Normal processing

        public void onError(ErrorInfo e) {
            // Handling an error

        public void onCancel() {
            // Handling a user cancel

        public void onFatal(ErrorInfo e) {
            // Handling an abnormal termination

Depending on the authentication results of the user, a corresponding Callback method is called. Respond by performing the appropriate processing procedures.

Obtaining error information

When an error occurred in the authorization process, ErrorInfo is returned so that you can obtain the details. See the following for the provided methods.

Type Method name Description
String getMessage Obtains error messages.
int getCode Obtains error codes. The HTTP status code value is returned.
boolean hasException Evaluates whether an exception has occurred.
Exception getException Returns an exception that occurred.

Checking the authorization status

Use the following method to check the current authorization status.

boolean MixiContainer#isAuthorized()

Usually, the authorization screen appears only for the first time. You can skip it thereafter as the isAuthorize method confirms it. If the user is authorized, true is returned; otherwise, false is returned.

Cancelling authorization

You can call the following method to cancel the authorization status. To protect users, be sure to implement this authorization cancel function when you use mixi API SDK for Android™.

void MixiContainer#logout(Activity activity, int activityCode, CallbackListener listener);