Customize a native Android app with the Mashup SDK
When you implement the Mashup SDK for Android in your native mobile app, you can use several advanced features to customize your native mobile app. For example, you can display a temporary screen before a Pega® Platform hybrid web view is loaded on to the app. You can also change the default error log level, use custom authentication, or pass custom parameters.
- Change hybrid web view settings
- Implement screen preloading
- Use custom parameters
- Implement custom authentication
Prerequisites
Before you continue, make sure you have set up the Mashup SDK for Android app development. In addition, make sure that you know how to do the following tasks:
Make sure that you also have access to the Mashup SDK Javadoc documentation that is included with the Pega Mashup SDK distribution package.
Change hybrid web view settings
You can use several methods for the ContainerSettings
object to change the default settings for the hybrid web view. For more information, see the Mashup SDK Javadoc documentation for the ContainerSettings
object.
For example, the following code demonstrates how to set the error debug level to DEBUG, log errors and warnings to a file, and set the connection time-out period to 90 seconds. Notice that the ContainerSettings
object methods are called inside the init()
method for the MainActivity
class when this object is initialized.
@ContainerActivity public class MainActivity extends ContainerMyActivity { @AfterContainerInit public void init() { ContainerSettings.setMinLogLevel(Log.DEBUG); ContainerSettings.setLogToFile(true); ContainerSettings.setConnectionTimeout(90); setContentView(R.layout.activity_main); } }
Implement screen preloading
When you call one of the Pega Platform actions by using the Mashup SDK, for example, to create a case, it might take a few seconds before the hybrid web view is shown on the screen where a user creates a case. You can add code in the onStart()
callback for the WebViewActionListener
object to display a temporary screen or a progress dialog box instead of a blank screen before the hybrid web view is displayed. This code is called before Pega Platform action execution.
For example, the following Java code demonstrates how to display a temporary progress dialog box before the hybrid web view is displayed.
private class CreateCaseListener extends SnapStart.WebViewActionListener { private Dialog progressDialog; @Override public void onStart() { // called before action execution progressDialog = ProgressDialog.show(getActivity(), getString(R.string.create_case_title), getString(R.string.create_case_msg)); progressDialog.setCancelable(false); } ... @Override public void onComplete() { progressDialog.dismiss(); } }
The following Java code demonstrates how to use the LoadingScreenHandler
object to display a temporary screen to the user before the hybrid web view is displayed. For more information, see the Mashup SDK Javadoc documentation for the LoadingScreenHandler
object.
// construct LoadingScreenHandler that presents given fragment on top of activity's content LoadingScreenHandler loadingScreenHandler = LoadingScreenHandler.create(ScreenPreloadingActivity.this, R.layout.fragment_loading); // pass LoadingScreenHandler to WebViewActionListener that displays loading screen while SnapStart action // result is loaded into HybridWebView WebViewActionListener webViewActionListener = new WebViewActionListener(loadingScreenHandler); // execute create case action within HybridWebview snapStart.createCase(webViewActionListener, hybridWebView, "className", "pyStartCase");
Use custom parameters
The Mashup SDK for Android allows you to pass the following types of parameters in the function calls to Pega Platform actions such as creating a case, opening a harness, or running an activity.
- Action parameters – Predefined parameters that are not directly called by a case or an activity. For more information, see Predefined action parameters for the Mashup SDK for Android.
- Rule parameters – Custom parameters that need to be used outside of the Mashup SDK.
The following Java code shows how to pass custom parameters by using the Mashup SDK. For more information, see the Mashup SDK Javadoc documentation for the SnapStartAction
object.
String className = "className"; String flowName = "pyStartCase"; boolean pyPhoneNavRuleMainVisible = false; boolean pyPhoneNavRuleToolbarVisible = false; // create optional parameter that will be passed to requested Pega rule SnapStartRuleParameter ruleParameter1 = new SnapStartRuleParameter("myCaseParam1", true); SnapStartRuleParameter ruleParameter2 = new SnapStartRuleParameter("myCaseParam2", "value"); // Use Builder for proper SnapStart action - Create case in this example: SnapStartAction.Builder action = new CreateCaseAction.Builder() .setClassName(className) .setFlowName(flowName) .setPyPhoneNavRuleMainVisible(pyPhoneNavRuleMainVisible) .setPyPhoneNavRuleToolbarVisible(pyPhoneNavRuleToolbarVisible) .addRuleParameters(ruleParameter1, ruleParameter2); SnapStart.ActionListener actionListener = new SnapStart.ActionListener() { // override ActionListener methods to handle Action result }; snapStart.executeAction(actionListener, action);
Implement custom authentication
If you plan to authenticate to the Pega Platform instance in a custom way, for example, for each login request you require an additional header or a parameter, you must use your own implementation of the ISnapStartAuthenticator
object to call the login()
method. For more information, see the Mashup SDK Javadoc documentation for the ISnapStartAuthenticator
object.
This interface object includes the following methods:
getHttpHeaders()
– The returned headers are added to every SnapStart HTTP request.getHttpPostParameters()
– The returned parameters are added to every SnapStart action.login()
– Authenticates to a Pega Platform application.logout()
– Signs out from a Pega Platform application.
class MySnapStartAuthenticator implements ISnapStartAuthenticator { @Override public String login() throws SnapStartLoginException { // used to log in using username/password and // Pega Platform instance url. } @Override public PegaAuthenticatorResult logout() { } @Override public Map<String, String> getHttpHeaders() { Map<String, String> headers = new HashMap<>(); headers.put("RequiredHeader", "ItsValue"); return headers; // the defined headers will be added to each // query of the SnapStart object instance } @Override public List<SnapStartActionParameter> getHttpPostParameters() { List<SnapStartActionParameter> params = new ArrayList<>(); params.add(new SnapStartActionParameter("RequiredParam", "ItsValue")); return params; // the defined parameters will be added to each // query of the SnapStart object instance } SnapStart mySnapStart; try { mySnapStart = SnapStart.login(new MySnapStartAuthenticator( /* add any arguments necessary to login here */)); } catch(SnapStartLoginException e){ // handle error }