Moxtra Meet SDK for Android

This guide outlines the stpes for you to get started quickly with the Moxtra Meet SDK for Android that will enable real-time screen sharing into your app.

Before proceeding further, ensure you have registered your app with Moxtra.

Step 1: Workspace Setup

Download Meet SDK for Android, unzip the downloaded file and follow the steps below.

Android Studio Setup

Now Android Studio is the official IDE for Android, and other IDEs should be migrated to Android Studio to get new features support. So we strongly recommend using Android Studio. If using eclipse or other IDE Moxtra SDK may not work as expected.

Start a new empty project or open your existing project and click "Import Module"

  • Android Studio v1.2 or higher: File -> New -> Import Module
     


     
  • Android Studio v1.1 or lower: File -> New -> Import Module
     


     

Select Moxtra SDK directory location, and click OK to import the Moxtra SDK into the project. NOTE: Moxtra SDK is contained in Moxtra SDK demo project, so import moxtra directory as module and do not need to import the whole demo project.

Moxtra Android SDK

Click on "Finish" to import Moxtra SDK module as shown below:

Moxtra Android SDK

Now, let's add the Moxtra SDK as a dependency to your project as shown below:

  • Select your Project -> Right Click on it -> Click on Open Module Settings
     


     
  • Select your project's app module(default module name) -> Open Dependencies tab -> Click Add (+) -> Choose Module dependency
     


     
  • Select "moxtra" SDK module -> Click OK
     


     

Now, define the following variables in the gradle.properties file as shown below. You may need to change the variables according to your dev environment and requirements.

ANDROID_BUILD_MIN_SDK_VERSION=14
ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=21.1
ANDROID_BUILD_SDK_VERSION=21

Step 2: Update AndroidMaifest.xml

There are some changes you need to make in AndroidManifest.xml to grant permissions and specify the required application components.

To enable the required features please add the following:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>

You must register your App in Moxtra developer website to get the client id and secret. Moxtra SDK can not work correctly if you do not do this. Do declare this part in AndroidManifest.xml.

<meta-data android:name="com.moxtra.sdk.ClientId" android:value="your_client_id" />
<meta-data android:name="com.moxtra.sdk.ClientSecret" android:value="your_client_secret" />

Set sandbox to "true" before your app go into production. After your app go to production, you should set it to "false".

<meta-data android:name="com.moxtra.sdk.SandboxEnv" android:value="true" />

To declare the required activities please add the following:

<activity
    android:name="com.moxtra.binder.activity.DialogFragmentActivity"
    android:theme="@style/MoxtraTheme"
    android:windowSoftInputMode="stateHidden|adjustResize" >
</activity>
<activity
    android:name="com.moxtra.binder.meet.MXLiveShareViewActivity"
    android:launchMode="singleTask"
    android:theme="@style/MoxtraTheme"
    android:windowSoftInputMode="stateHidden|adjustPan" >
</activity>
<activity
    android:name="com.moxtra.binder.MXTransparentActivity"
    android:launchMode="singleTask"
    android:theme="@style/MoxFullTranslucentActivity"
    android:windowSoftInputMode="stateHidden|adjustPan" >
</activity>
<activity
    android:name="com.moxtra.binder.livemeet.MXSDKMeetActivity"
    android:launchMode="singleTask"
    android:theme="@style/MoxtraTheme">
</activity>
<service android:name="com.moxtra.sdk.MoxtraMeetSdkService" />
<activity
    android:name="com.moxtra.binder.activity.MXStackActivity"
    android:theme="@style/MXActivityDialog"
    android:windowSoftInputMode="stateHidden|adjustResize" >
</activity>
<activity
    android:name="com.moxtra.binder.member.MXInviteActivity"
    android:theme="@style/MXActivityDialog"
    android:windowSoftInputMode="stateHidden" >
</activity>
<activity
    android:name="com.moxtra.binder.conversation.MXConversationActivity"
    android:launchMode="singleTask"
    android:windowSoftInputMode="stateHidden|adjustResize"
    android:theme="@style/MoxtraTheme" >
</activity>
<activity 
    android:name="com.moxtra.binder.pageview.PageViewActivity"
    android:launchMode="singleTask"
    android:windowSoftInputMode="stateHidden|adjustPan"
    android:theme="@style/MoxtraTheme" >
</activity>
<activity 
    android:name="com.moxtra.binder.livemeet.LiveMeetActivity"
    android:launchMode="singleTask"
    android:theme="@style/MoxtraTheme" >
</activity>
<activity 
    android:name="com.moxtra.binder.multiimagepicker.MultiImagePickerActivity"
    android:theme="@style/MoxtraTheme" >
</activity>
<activity
    android:name="com.moxtra.binder.util.MXAlertDialog"
    android:theme="@style/MoxFullTranslucentActivity"
    android:windowSoftInputMode="stateHidden" >
</activity>
<activity android:name="com.moxtra.binder.search.MXSearchActivity" android:theme="@style/MoxtraTheme"/>
<activity android:name="com.moxtra.binder.webnote.MXWebNoteActivity" android:theme="@style/MoxtraTheme"/>
<activity android:name="com.moxtra.binder.webclip.MXWebClipActivity" android:theme="@style/MoxtraTheme"/>
<activity android:name="com.moxtra.binder.livemeet.MeetRingActivity" android:theme="@style/MoxtraTheme"/>
<service android:name=".service.AudioPlayerService" />

For better user expierence, defined the below-mentioned theme or use MoxtraTheme (in res/values/styles.xml):

<style name="MoxtraTheme" parent="AppBaseTheme">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowAnimationStyle">@style/MoxActivityAnimation</item>
    <item name="android:textViewStyle">@style/MoxTextViewBase</item>
    <item name="android:listViewStyle">@style/MoxListViewBase</item>
</style>

For more information on the AndroidManifest.xml file see this link.

Step 3: Implement the login/logout function

We will not have signup in our demo app but using the dummy data we created in step 3.

Also, we will not cover everything about the login but only the Moxtra Chat SDK related part. All the user management should be done in your app. The Moxtra Chat SDK could not help on the part.

What we need to do for login is:

Login Flow

First, let's initialize the MXAccountManager. We recommend to initialize the MXAccountManager very first when starting the app. So it's a good place to init it in your Application. In our app, we init it in the MoxieChatApplication. Here is the code:

@Override
public void onCreate() {
    super.onCreate();
    try {
        MXAccountManager.createInstance(this);
    } catch (MXSDKException.InvalidParameter invalidParameter) {
        Log.e(TAG, "Error when creating MXAccountManager instance.", invalidParameter);
    }
}

After login success on the app, we need to setup the user in Moxtra so we can use the moxtra service.

We will add it in the LoginActivity.

// Login success and then setup user on Moxtra
User user = PreferenceUtil.getUser(LoginActivity.this);
try {
    Bitmap avatar = BitmapFactory.decodeStream(LoginActivity.this.getAssets().open(user.avatarPath));
    MXSDKConfig.MXUserInfo mxUserInfo = new MXSDKConfig.MXUserInfo(user.email, MXSDKConfig.MXUserIdentityType.IdentityUniqueId);
    MXSDKConfig.MXProfileInfo mxProfileInfo = new MXSDKConfig.MXProfileInfo(user.firstName, user.lastName, avatar);
    MXAccountManager.getInstance().setupUser(mxUserInfo, mxProfileInfo, null, null, LoginActivity.this);
} catch (IOException e) {
    Log.e(TAG, "Can't decode avatar.", e);
}

The setupUser is an async operation and we have to pass a callback to it. In our code, the callback the the LoginActivity which means we have to implement the callback interface. Here is the code:

@Override
public void onLinkAccountDone(boolean success) {
    if (success) {
        Log.i(TAG, "Linked to moxtra account successfully.");
        startConferenceListActivity();
    } else {
        Toast.makeText(this, "Failed to setup moxtra user.", Toast.LENGTH_LONG).show();
        Log.e(TAG, "Failed to setup moxtra user.");
        showProgress(false);
    }
}

For the logout, you should unlink the Moxtra account after user successfully logout from your app. In our demo app, it was implemented in the BaseActivity Action Toolbar so user can logout from any activity that extends from BaseActivity.

MXAccountManager.getInstance().unlinkAccount(this);

Step 4: Start Meet

To start and join a screen sharing session of your app, you need first get an instance of MXMeetManager. With this instance you will be able to make the calls related to meet/screenshare session as mentioned in this section:

Get Instance

Get an instance of Moxtra Meet Manager.

static public MXMeetManager getInstance();

Example:

MXMeetManager meetMgr = MXMeetManager.getInstance();

Start Meet

public void startMeet(String topic, String guideMessage, OnStartMeetListener listener);

Start meet method to screen share, voice call and chat.

Parameters:

      topic - Topic for the meet.
      guideMessage - Customized content of the invitation message.
      listener - Callback to notify about the events of Meet

Exceptions:

      Unauthorized - User not not initialized successfully.
      MeetIsInProgress - Another meet session already in progress.

Example:

meetMgr.startScreenShareMeet(“Moxtra Meet”,”Welcome to Join My Moxtra Meet!”,
new OnStartMeetListener(){
    @Override
    public void onStartMeetDone(String meetId, String meetUrl){
        //Add code to send url for invitation here
    }

    @Override
    public void onStartMeetFailed(int errorCode, String message) {
        // handle the failure
    }
});

Step 5: Invite Users to Meet

public void inviteParticipants(List invitees);

Invite users to join meet after successful start of meet. (N/A if your app is using Moxtra Identity to initialize the user).

Parameters:

      invitees - list of user identities to be invited for the meet.

Exceptions:

      MeetIsNotStarted - Meet is not in progress.

Example:

meetMgr.inviteParticipants(invitees);

Step 6: Join Meet

public void joinMeet(String meetId, String userName, OnJoinMeetListener listener);

Call to join an existing Moxtra meet session.

Parameters:

      meetId - Moxtra meet ID
      userName - Name of the user joining the meet (set this to null if using unique user identity based authentication model)
      listener - Callback to notify about the events of Meet

Exceptions:

      Unauthorized - User not not initialized successfully (if using unique user identity based authentication model).
      MeetIsInProgress - Another meet session already in progress.

Example:

meetMgr.setOnEndMeetListener(new MXMeetManager.OnEndMeetListener() {
    @Override
    public void onMeetEnded(String meetID) {
        // add code here
    }
});

Step 7: Callback for End Meet

public void setOnEndMeetListener(OnEndMeetListener listener)

Register Meet ended listener.

Parameters:

      listener - Callback to notify about the events of End Meet

Example:

MXMeetManager.getInstance().setOnEndMeetListener(new MXMeetManager.OnEndMeetListener() {
    @Override
    public void onMeetEnded(String meetID) {
    // add code here
    }
});

API Reference

We just covered a few APIs in the tutorial. For the full list of APIs please refer to our Android Meet SDK: API Reference Guide.