Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

This content has been archived and is no longer being updated.

Links may not function; however, this content may be relevant to outdated versions of the product.

Setting up the Connect SDK for Android app development

Updated on March 16, 2020

To set up the Connect SDK in Android Studio so that its API can be used in Android mobile apps that are being developed, follow the instructions provided in the sections below.

Prerequisites

Before you start developing an Android app that uses the Connect SDK, make sure that you have access to the following items:

  • Android Studio 1.2 or later
  • Android SDK with API level 14 or later
  • Android device or Android emulator

Additionally, do the following tasks:

  • Read the Connect SDK overview article.
  • Read the Connect SDK JavaDocs, which describe the API.
The users of the Pega ® Platform mobile app that you are creating must have the PegaRULES:PegaAPI role assigned to them.

Create an Android application project

To create an Android application project that is able to use the Connect SDK, do the following steps:

  1. In Android Studio, click File > New > New Project to start the New Project wizard.
  2. Select the Phone and Tablet platform.
  3. Select Minimum SDK API 14 or higher.

Add the Connect SDK library

To set up the Connect SDK in the Android Studio environment, do the following steps:

These steps include adding dependencies with Gradle.
  1. Copy the Connect SDK library file, connectsdk.pegaapi-3.1.0.0.aar, that you have received from Pegasystems to the /libs folder in your Android module. By default, the module name is 'app' and the path that is relative to your project root directory consists of app/libs.
  2. Open the build.gradle file in the Android module (not the one at the top level of the project) and add the following code to it. Additionally, append the Connect SDK and its dependencies to the 'dependencies' section at the top level of the file:
    repositories {
      (...)
      flatDir {
        dirs 'lib'
      }
    ​}
    ​(...)
    ​dependencies { 
      (...)
      compile 'com.pega:connectsdk.pegaapi-3.2.0.0@aar' 
      compile 'com.android.support:support-v4:26.1.0'
      compile 'com.android.support:appcompat-v7:26.1.0'
      compile 'com.google.android.gms:play-services-gcm:11.8.0'
      compile 'com.fasterxml.jackson.core:jackson-databind:2.1.4'
      compile 'com.google.dagger:dagger:2.0'
      compile 'com.squareup.okhttp3:okhttp:3.8.1'
    ​}
  3. Compile and run the application.

Verify that the Connect SDK library is configured

You can now test whether the Connect SDK has been correctly configured in Android Studio by adding the following code to the Android app that you are creating.

  1. Create the code for the PegaSingleton class. Set the Pega API URL in an instance of a Configuration object by replacing the <server URL> string with your Pega Platform application instance URL.
    import com.pega.connectsdk.pegaapi.Pega; 
      
    public class PegaSingleton {
      private static final String PEGA_URL = "https://server_url_address";
      private static final PegaSingleton INSTANCE = new PegaSingleton();
    ​
      private Pega pega; 
      
      private PegaSingleton() { 
        this.pega = Pega.create(); 
        this.pega.configuration().setServerUrl(PEGA_URL);
      } 
      
      public static Pega getInstance() {
        return INSTANCE.pega;
      } 
    ​}
  2. In the MainActivity class, initialize this new object inside the onCreate() method. Also make sure to invoke the authenticate() method.< br/>
    @Override   
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 
      authenticate();
    ​}
  3. Define the authenticate() method in the MainActivity class. Remember that before you call the Connect SDK, you must authenticate by replacing the <user name> and <password> strings in the following code with your Pega Platform application credentials:
    private void authenticate() { 
      Pega pega = PegaSingleton.getInstance();
      if(!pega.authentication().isLoggedIn()) { 
        Authentication.LoginCallback loginCallback = new Authentication.LoginCallback() { 
          @Override 
          public void onSuccess(){ 
            // pega instance is ready to use
          } 
      
          @Override 
          public void onFailure(ErrorResponse errorResponse) { 
            // handle authentication error here
          }
        } 
        pega.authentication().login("", "", loginCallback);
      } 
    ​}

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us