Setting up the Mashup SDK for Android app development
You can set up the Mashup SDK in the Android Studio development environment to use its API to develop native Android apps that embed one or more screens of a Pega® Platform application as hybrid web views. For example, an existing Android app used for banking purposes might also need to allow its users to dispute credit card transactions by opening a case in a separate Pega Platform application.
Prerequisites
You must develop the native Android app that uses the Mashup SDK by using one of the following IDEs:
- Android Studio 2.2.3
- IntelliJ IDEA 2016.x or 2017.x
Make sure that you have completed the following prerequisites:
- Have experience developing Android apps
- Download the Pega Mashup SDK version 7.31.x distribution package that contains the following items:
- The Mashup SDK library and additional external libraries
- The Mashup SDK Javadoc documentation
- A demo application that uses the Mashup SDK
External libraries for Android
The Mashup SDK is distributed with and uses the following external libraries for the Android platform. Only the following library versions are supported:
- com.android.support:support-v4:24.2.0
- com.android.support:support-annotations:24.2.0
- com.google:zxing-core:20140304
- net.zetetic:android-database-sqlcipher:3.5.3.vol1
- org.greenrobot:eventbus:3.0.0
- javax:inject:1
- com.squareup.dagger:dagger:1.2.2.vol1
- com.squareup.dagger:dagger-compiler:1.2.2.vol1
- com.squareup:javawriter:2.5.1
- com.google.android.gms:play-services-location:9.4.0
- com.google.android.gms:play-services-gcm:9.4.0
- com.squareup.okhttp:okhttp:2.7.4
- com.squareup.okio:okio:1.6.0
- com.google.code.gson:gson:2.2.4
Adding the app with the Mashup SDK to an Android Studio project
To configure the Mashup SDK in a project, perform the following steps. You must edit the build.gradle and AndroidManifest.xml files, and optionally, change the default container settings by calling its API methods during initialization.
- Create or open a project in Android Studio or IntelliJ IDEA.
- If the build.gradle file does not exist, create it for the application. Edit the file and append the following text in the
repositories{}
section:repositories { maven { url "file:///repository" } }
- Append the following text in the
dependencies{}
section of the application build.gradle file:- If you are using Android Gradle plugin 2.2.0 or later:
dependencies { compile 'com.pega:mashupSdk:7.31' annotationProcessor 'com.pega.commontools:android-annotation:1.9.4-SNAPSHOT' }
- If you are using an earlier version of the Android Gradle plugin:
buildscript { dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } apply plugin: 'com.neenbedankt.android-apt' } dependencies { compile 'com.pega:mashupSdk:7.31' apt 'com.pega.commontools:android-annotation:1.9.4-SNAPSHOT' }
- If you are using Android Gradle plugin 2.2.0 or later:
- Make sure your application class, for example,
MyApplication
class is inherited from theContainerApplication
class. Otherwise, add the following code to theonCreate()
method for this class:public class MyApplication extends Application { ... public void onCreate() { Container.init( this ); ... } }
- Edit the AndroidManifest.xml file and add the
android:configChanges="screenSize|orientation”
line inside the activity XML element:<activity android:name="com.pega.mashup.MainActivity" android:configChanges="screenSize|orientation"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
- Each
Activity
class in which you display a Pega Platform application screen must be annotated with@com.pega.mobile.activity.ContainerActivity
:@com.pega.mobile.activity.ContainerActivity( android.support.v7.app.AppCompatActivity.class ) public class com.example.app.MyActivity extends com.example.app.ContainerMyActivity { ... }
- Optional: Change the default container settings by calling any of the API methods for the
ContainerSettings
object that is listed in the following Container settings API section table, for example:@ContainerActivity public class MainActivity extends ContainerMainActivity { @AfterContainerInit public void init() { ContainerSettings.setConnectionTimeout(180); ContainerSettings.setWebViewBackground("#000000"); setContentView(R.layout.activity_main); } ... }
Container settings API
To change the default values for the container, for example, connection time-out, hybrid web view background color, or log level, you can use a set of functions in an API for the ContainerSettings
object. You must set these settings in either of the following places:
- The
onCreate()
method for the implementation of the application class. - The
init()
or other any function that is preceded with@AfterContainerInit
inside the activity.
Function name | Description | Default value |
---|---|---|
| Specifies the time-out, in seconds, for downloading one resource. | 360 |
setConnectionTimeout( int ) | Specifies the connection time-out, in seconds, for new connections. A value of 0 means that no time-out is used. | 60 |
setLogToConsole( boolean ) | Enables writing logs to the system console. The logs are read by using logcat. | true |
setLogToFile( boolean ) | Enables writing logs to a file. Logs written to a file are read by using the JavaScript API. | false |
setMinLogLevel( int ) | Sets the default log level for the container to: Silent, Error, Warning, Info, Debug, or Verbose. The Verbose log level is intended only for development purposes because it logs sensitive user information such as passwords. | Info |
setOnPageFinished( int ) | Specifies the time-out, in seconds, for the onPageFinished action. | 180 |
setTotalDiskQuota( int ) | Specifies the approximate maximum disk space, in MB, for the log file. | 20 |
setWebViewBackground( string ) | Specifies the background color of the application hybrid web views in the RGB string format: '#AARRGGBB' . |
Changing container settings example
The following code sets the connection time-out for the container to 90 seconds and the hybrid web view background color to white (RGB value of '#FFFFFF'). Note that you set these settings in the init()
function.
@ContainerActivity public class MainActivity extends ContainerMyActivity { @AfterContainerInit public void init() { ContainerSettings.setConnectionTimeout(90); ContainerSettings.setWebViewBackground("#FFFFFF"); ContainerSettings.setMinLogLevel(Log.DEBUG); setContentView(R.layout.activity_main); } }