The following steps are covered in the Android Up and Running Demo so we can go ahead and set them up before starting the new video.
- Open Android Studio
- New Project
- Name application :
EngageIdentityDemo
- Set company domain :
silverpop.com
- Choose project location
- Click next
- Make sure the box for 'Phone and Tablet' is checked
- Set Minimum SDK to 19 or lower > Next
- Select 'Blank Activity'
- Name activity to your liking - I'm keeping defaults
- Finish
- Turn on autoscroll to/from source (This step is optional, but it makes the demo nicer because you can see where the open files live in the project tree as we access them)
- Uncheck 'Compact Empty Middle Packages' (Also optional, but it makes it easier to see the directory structure)
- Switch the Project tool window from 'Android' to 'Project'
- The EngageSDK isn't in Maven yet so for now we'll manually add the dependency
- In the Project tool window, right click the
app
folder > New Directory > nameaars
> Ok - Copy/paste the
engage-1.1.0.aar
into newaars
directory (you can either build this yourself or have Silverpop provide it for you) - Open
build.grade
from Gradle tool window and add the following
repositories {
flatDir {
dirs 'aars'
}
}
dependencies {
// use this once maven support is added
//compile(group: 'com.silverpop', name: 'engage', version: '1.1.0', ext: 'aar')
compile 'com.silverpop:engage:1.1.0@aar'
}
- Sync Gradle to pull in your new changes
- Right click the
engagedemo
package > New > Java Class - Name the new class
Application
> Ok - Modify the
Application
class to extendEngageApplication
package com.silverpop.engagedemo;
import com.silverpop.engage.EngageApplication;
public class Application extends EngageApplication {
}
- Open
AndroidManifest.xml
- Add an attribute to the
application
xml with the full class name of your newApplication.java
class
android:name="com.silverpop.engagedemo.Application"
- Open
AndroidManifest.xml
- In the
application
xml block add your credentials
<meta-data android:name="ENGAGE_CLIENT_ID" android:value="02eb567b-3674-4c48-8418-dbf17e0194fc" />
<meta-data android:name="ENGAGE_CLIENT_SECRET_META" android:value="9c650c5b-bcb8-4eb3-bf0a-cc8ad9f41580" />
<meta-data android:name="ENGAGE_REFRESH_TOKEN" android:value="676476e8-2d1f-45f9-9460-a2489640f41a" />
<meta-data android:name="ENGAGE_HOST" android:value="https://apipilot.silverpop.com/" />
Today we are going to demonstrate configuring mobile idenities using the Android Engage SDK. We are making the assumption that you've already watched the Android Up And Running video so we're going to jump right in.
I've already configured my new Android Studio project with the needed configuration settings (show them).
- Added engage-1.1.0.aar
- Gradle Config
- Custom
Application
that extendsEngageApplication
AndroidManifest.xml
is configured with customApplication
AndroidManifest.xml
is configured with credentialsEngageConfig.json
is added toassets
directory
But before we can add the new functionality there are a few things you need to Setup on the silverpop side. The first is that you'll need to configure your recipient lists with columns for
- Mobile User Id
- Merged Recipient Id
- Merged Date
You also have the option for creating a separate AuditRecord table if you'd prefer to track recipient merge history there. You'll need to set that up with columns for
- Audit Record Id
- Old Recipient Id
- New Recipient Id
- Create Date if you wish to use that. If you any help with this configuration please contact Silverpop support.
You'll also need to have your recipient table pre-configured with any custom id columns you wish - facebook_id, etc.
My recipient table is currently setup with a custom id column called "Custom Integration Test Id" so that's what I'm going to use for the demo.
- Open
activity_main.xml
- In the Design tab set the
id
of the Hello WorldTextView
tocurrentConfigView
- Set the
minLines
property to 5 - Set the
layoutWidth
tomatch_parent
- Change to Text tab and verify you changed the correct settings
- Change the 'Hello World' text to say 'Current Config:'
- Add 'Setup Recipient' button with
setupRecipientBtn
as the id - Add 'Check Identity' button with
checkIdentityBtn
as the id
- Open
MainActivity.java
and update it with the following
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button setupRecipientBtn = (Button)findViewById(R.id.setupRecipientBtn);
setupRecipientBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MobileIdentityManager.get().setupRecipient(new SetupRecipientHandler() {
@Override
public void onSuccess(SetupRecipientResult setupRecipientResult) {
updateConfigStatus();
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).showToast();
}
@Override
public void onFailure(SetupRecipientFailure setupRecipientFailure) {
Toast.makeText(getApplicationContext(), "ERROR", Toast.LENGTH_SHORT).showToast();
}
});
}
});
Button checkIdentityBtn = (Button)findViewById(R.id.checkIdentityBtn);
checkIdentityBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Map<String, String> ids = new HashMap<String, String>();
ids.put("Custom Integration Test Id", "09890809809");
MobileIdentityManager.get().checkIdentity(ids, new CheckIdentityHandler() {
@Override
public void onSuccess(CheckIdentityResult checkIdentityResult) {
Toast.makeText(getApplicationContext(), "Check identity success", Toast.LENGTH_SHORT).showToast();
}
@Override
public void onFailure(CheckIdentityFailure checkIdentityFailure) {
Toast.makeText(getApplicationContext(), "ERROR", Toast.LENGTH_SHORT).showToast();
}
});
}
});
}
private void updateConfigStatus() {
TextView config = (TextView)findViewById(R.id.configStatusText);
config.setText(String.format("Config\nRecipient Id:\n%s\nMobile User Id\n%s",
EngageConfig.recipientId(getApplicationContext()),
EngageConfig.mobileUserId(getApplicationContext())));
}
- Click the run button and wait for the emulator to start
- Click Setup recipient and wait for the config to change
- Click Check Identity