Implement features


In the previous section, you learned how to implement a simple UI in your app.

This section demonstrates how to make the buttons interactive by adding functions that enable the Join Meeting and Login and Start Meeting features. You will enable these features by using the MeetingService interface provided by Zoom Meeting SDK.

1. Join a meeting

The Join Meeting feature of this demo app should allow a participant to join an existing Zoom meeting once they enter the Meeting Number and Meeting Passcode (if one exists) for the meeting.

To implement this feature, add the following lines of code in your MainActivity.java file below the initializeSDK method:

MainActivity.java
//1. Write the joinMeeting function.
private void joinMeeting(Context context, String meetingNumber, String password) {
  MeetingService meetingService = ZoomSDK.getInstance().getMeetingService();
  JoinMeetingOptions options = new JoinMeetingOptions();
  JoinMeetingParams params = new JoinMeetingParams();
  params.displayName = ""; // TODO: Enter your name
  params.meetingNo = meetingNumber;
  params.password = password;
  meetingService.joinMeetingWithParams(context, params, options);
}

The joinMeeting function accepts meeting number(meeting ID) and meeting passcode as parameters and passes these parameters to the joinMeetingWithParams method.

2. Login and start a meeting

The Login & Start Meeting button of this demo app should prompt the user to login with Zoom login credentials if the user is not already loggen in. After successfully logging in, the user will join an instant meeting as a Meeting host.

To implement the Login & Start Meeting feature, add the following lines of code in your MainActivity.java file under the joinMeeting method:

MainActivity.java
// 1. Write the login function

private void login(String username, String password) {
  int result = ZoomSDK.getInstance().loginWithZoom(username, password);
  if (result == ZoomApiError.ZOOM_API_ERROR_SUCCESS) {

    // 2. After request is executed, listen for the authentication result prior to starting a meeting
    ZoomSDK.getInstance().addAuthenticationListener(authListener);
  }
}
// 3. Write the startMeeting function
private void startMeeting(Context context) {
  ZoomSDK sdk = ZoomSDK.getInstance();
  if (sdk.isLoggedIn()) {
    MeetingService meetingService = sdk.getMeetingService();
    StartMeetingOptions options = new StartMeetingOptions();
    meetingService.startInstantMeeting(context, options);
  }
}

Next, in MainActivity.java, add createJoinMeetingDialog() and createLoginDialog() methods that implement the following behaviors:

  1. Utilize the AlertDialog interface to display dialogs with custom layouts that we created earlier for login and meeting information.

  2. Verify that the information entered by the user is valid when the button is clicked and call associated methods(joinMeeting and startMeeting) upon validation.

MainActivity.java
// 1. Create a dialog where a participant can enter the meeting information to join a meeting.
private void createJoinMeetingDialog() {
  new AlertDialog.Builder(this).setView(R.layout.dialog_join_meeting).setPositiveButton("Join", new DialogInterface.OnClickListener() {@Override
    public void onClick(DialogInterface dialogInterface, int i) {
      AlertDialog dialog = (AlertDialog) dialogInterface;
      TextInputEditText numberInput = dialog.findViewById(R.id.meeting_no_input);
      TextInputEditText passwordInput = dialog.findViewById(R.id.password_input);
      if (numberInput != null && numberInput.getText() != null && passwordInput != null && passwordInput.getText() != null) {
        String meetingNumber = numberInput.getText().toString();
        String password = passwordInput.getText().toString();
        if (meetingNumber.trim().length() > 0 && password.trim().length() > 0) {
          joinMeeting(MainActivity.this, meetingNumber, password);
        }
      }
    }
  }).show();
}

// 2. Create a dialog where a host can enter Zoom email and password to login and start an instant meeting.
private void createLoginDialog() {
  new AlertDialog.Builder(this).setView(R.layout.dialog_login).setPositiveButton("Log in", new DialogInterface.OnClickListener() {@Override
    public void onClick(DialogInterface dialogInterface, int i) {
      AlertDialog dialog = (AlertDialog) dialogInterface;
      TextInputEditText emailInput = dialog.findViewById(R.id.email_input);
      TextInputEditText passwordInput = dialog.findViewById(R.id.pw_input);
      if (emailInput != null && emailInput.getText() != null && passwordInput != null && passwordInput.getText() != null) {
        String email = emailInput.getText().toString();
        String password = passwordInput.getText().toString();
        if (email.trim().length() > 0 && password.trim().length() > 0) {
          login(email, password);
        }
      }
    }
  }).show();
}

Create a method named initViews that handles the onClick events for the Join Meeting and Login & Start Meeting buttons.

MainActivity.java
//1. Write initViews method to handle onClick events for the Join Meeting and Login & Start Meeting buttons. 
private void initViews() {
  findViewById(R.id.join_button).setOnClickListener(new View.OnClickListener() {@Override
    public void onClick(View view) {
      createJoinMeetingDialog();
    }
  });

  findViewById(R.id.login_button).setOnClickListener(new View.OnClickListener() {@Override
    public void onClick(View view) {
      // 2.  If a user is logged in, start the instant meeting, else prompt the user to login.
      if (ZoomSDK.getInstance().isLoggedIn()) {
        startMeeting(MainActivity.this);
      } else {
        createLoginDialog();
      }
    }
  });
}

When the Join Meeting button is pressed, the createJoinMeetingDialog method gets invoked which displays the dialog for users to enter the meeting information. Similarly, when the Login & Start Meeting button is clicked, createLoginDialog method gets invoked which displays the dialog for users to enter their Zoom login information.

Upon successful login, the user will immediately join an instant meeting as a host. If the user is already logged in, this will just start the instant meeting.

Note that to use AlertDialog, we need to import the AlertDialog and DialogInterfaces packages in our MainActivity.java file.

Refer to the following snippet to see what your complete MainActivity.java file should look like:

MainActivity.java
// The package name will be different for your project.
package com.example.myzoomsdkandroidapplication;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.google.android.material.textfield.TextInputEditText;

import us.zoom.sdk.JoinMeetingOptions;
import us.zoom.sdk.JoinMeetingParams;
import us.zoom.sdk.MeetingService;
import us.zoom.sdk.StartMeetingOptions;
import us.zoom.sdk.ZoomApiError;
import us.zoom.sdk.ZoomAuthenticationError;
import us.zoom.sdk.ZoomSDK;
import us.zoom.sdk.ZoomSDKAuthenticationListener;
import us.zoom.sdk.ZoomSDKInitParams;
import us.zoom.sdk.ZoomSDKInitializeListener;

public class MainActivity extends AppCompatActivity {
  private ZoomSDKAuthenticationListener authListener = new ZoomSDKAuthenticationListener() {
    /**
        * This callback is invoked when a result from the SDK's request to the auth server is
        * received.
        */
    @Override
    public void onZoomSDKLoginResult(long result) {
      if (result == ZoomAuthenticationError.ZOOM_AUTH_ERROR_SUCCESS) {
        // Once we verify that the request was successful, we may start the meeting
        startMeeting(MainActivity.this);
      }
    }

    @Override
    public void onZoomSDKLogoutResult(long l) {}@Override
    public void onZoomIdentityExpired() {}@Override
    public void onZoomAuthIdentityExpired() {}
  };

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    initializeSdk(this);
    initViews();
  }

  /**
    * Initialize the SDK with your credentials. This is required before accessing any of the
    * SDK's meeting-related functionality.
    */
  public void initializeSdk(Context context) {
    ZoomSDK sdk = ZoomSDK.getInstance();
    // TODO: Do not use hard-coded values for your key/secret in your app in production!
    ZoomSDKInitParams params = new ZoomSDKInitParams();
    params.appKey = ""; // TODO: Retrieve your SDK key and enter it here
    params.appSecret = ""; // TODO: Retrieve your SDK secret and enter it here
    params.domain = "zoom.us";
    params.enableLog = true;
    // TODO: Add functionality to this listener (e.g. logs for debugging)
    ZoomSDKInitializeListener listener = new ZoomSDKInitializeListener() {
      /**
            * @param errorCode {@link us.zoom.sdk.ZoomError#ZOOM_ERROR_SUCCESS} if the SDK has been initialized successfully.
            */
      @Override
      public void onZoomSDKInitializeResult(int errorCode, int internalErrorCode) {}

      @Override
      public void onZoomAuthIdentityExpired() {}
    };
    sdk.initialize(context, listener, params);
  }

  private void initViews() {
    findViewById(R.id.join_button).setOnClickListener(new View.OnClickListener() {@Override
      public void onClick(View view) {
        createJoinMeetingDialog();
      }
    });

    findViewById(R.id.login_button).setOnClickListener(new View.OnClickListener() {@Override
      public void onClick(View view) {
        if (ZoomSDK.getInstance().isLoggedIn()) {
          startMeeting(MainActivity.this);
        } else {
          createLoginDialog();
        }
      }
    });
  }

  /**
    * Join a meeting without any login/authentication with the meeting's number & password
    */
  public void joinMeeting(Context context, String meetingNumber, String password) {
    MeetingService meetingService = ZoomSDK.getInstance().getMeetingService();
    JoinMeetingOptions options = new JoinMeetingOptions();
    JoinMeetingParams params = new JoinMeetingParams();
    params.displayName = ""; // TODO: Enter your name
    params.meetingNo = meetingNumber;
    params.password = password;
    meetingService.joinMeetingWithParams(context, params, options);
  }

  /**
    * Log into a Zoom account through the SDK using your email and password. For more information,
    * see {@link ZoomSDKAuthenticationListener#onZoomSDKLoginResult} in the {@link #authListener}.
    */
  public void login(String username, String password) {
    int result = ZoomSDK.getInstance().loginWithZoom(username, password);
    if (result == ZoomApiError.ZOOM_API_ERROR_SUCCESS) {
      // Request executed, listen for result to start meeting
      ZoomSDK.getInstance().addAuthenticationListener(authListener);
    }
  }

  /**
    * Start an instant meeting as a logged-in user. An instant meeting has a meeting number and
    * password generated when it is created.
    */
  public void startMeeting(Context context) {
    ZoomSDK sdk = ZoomSDK.getInstance();
    if (sdk.isLoggedIn()) {
      MeetingService meetingService = sdk.getMeetingService();
      StartMeetingOptions options = new StartMeetingOptions();
      meetingService.startInstantMeeting(context, options);
    }
  }

  /**
    * Prompt the user to input the meeting number and password and uses the Zoom SDK to join the
    * meeting.
    */
  private void createJoinMeetingDialog() {
    new AlertDialog.Builder(this).setView(R.layout.dialog_join_meeting).setPositiveButton("Join", new DialogInterface.OnClickListener() {@Override
      public void onClick(DialogInterface dialogInterface, int i) {
        AlertDialog dialog = (AlertDialog) dialogInterface;
        TextInputEditText numberInput = dialog.findViewById(R.id.meeting_no_input);
        TextInputEditText passwordInput = dialog.findViewById(R.id.password_input);
        if (numberInput != null && numberInput.getText() != null && passwordInput != null && passwordInput.getText() != null) {
          String meetingNumber = numberInput.getText().toString();
          String password = passwordInput.getText().toString();
          if (meetingNumber.trim().length() > 0 && password.trim().length() > 0) {
            joinMeeting(MainActivity.this, meetingNumber, password);
          }
        }
        dialog.dismiss();
      }
    }).show();
  }

  /**
    * Prompts the user to input their account email and password and uses the Zoom SDK to login.
    * See {@link ZoomSDKAuthenticationListener#onZoomSDKLoginResult} in the {@link #authListener} for more information.
    */
  private void createLoginDialog() {
    new AlertDialog.Builder(this).setView(R.layout.dialog_login).setPositiveButton("Log in", new DialogInterface.OnClickListener() {@Override
      public void onClick(DialogInterface dialogInterface, int i) {
        AlertDialog dialog = (AlertDialog) dialogInterface;
        TextInputEditText emailInput = dialog.findViewById(R.id.email_input);
        TextInputEditText passwordInput = dialog.findViewById(R.id.pw_input);
        if (emailInput != null && emailInput.getText() != null && passwordInput != null && passwordInput.getText() != null) {
          String email = emailInput.getText().toString();
          String password = passwordInput.getText().toString();
          if (email.trim().length() > 0 && password.trim().length() > 0) {
            login(email, password);
          }
        }
        dialog.dismiss();
      }
    }).show();
  }
}

Run your app

Connect your Android device and press Run to run your app on your device. If you do not have an Android device handy, you can also run this app on your emulator.

Press the “Join Meeting” button to join a meeting as a participant or press the “Login & Start Meeting” button to start an instant meeting as a meeting host. Once you enter the meeting, you can see the Zoom UI and functionalities integrated in your app. Note that this demo app assumes you will enter valid input and may not provide feedback if information is not entered correctly (e.g. incorrect password).

Next steps

This was a simple quickstart made to get you up and running with the Zoom Meeting SDK. Next, explore the sample apps included in your downloaded SDK package (sample and example2) and read the SDK docs to understand and implement advanced features.