in LexSample/app/src/main/java/com/amazonaws/sample/lex/TextActivity.java [143:198]
private void initializeLexSDK() {
Log.d(TAG, "Lex Client");
// Initialize the mobile client
AWSMobileClient.getInstance().initialize(this, new Callback<UserStateDetails>() {
@Override
public void onResult(UserStateDetails result) {
Log.d(TAG, "initialize.onResult, userState: " + result.getUserState().toString());
// Identity ID is not available until we make a call to get credentials, which also
// caches identity ID.
AWSMobileClient.getInstance().getCredentials();
String identityId = AWSMobileClient.getInstance().getIdentityId();
Log.d(TAG, "identityId: " + identityId);
String botName = null;
String botAlias = null;
String botRegion = null;
JSONObject lexConfig;
try {
lexConfig = AWSMobileClient.getInstance().getConfiguration().optJsonObject("Lex");
lexConfig = lexConfig.getJSONObject(lexConfig.keys().next());
botName = lexConfig.getString("Name");
botAlias = lexConfig.getString("Alias");
botRegion = lexConfig.getString("Region");
} catch (JSONException e) {
Log.e(TAG, "onResult: Failed to read configuration", e);
}
InteractionConfig lexInteractionConfig = new InteractionConfig(
botName,
botAlias,
identityId);
lexInteractionClient = new InteractionClient(getApplicationContext(),
AWSMobileClient.getInstance(),
Regions.fromName(botRegion),
lexInteractionConfig);
lexInteractionClient.setAudioPlaybackListener(audioPlaybackListener);
lexInteractionClient.setInteractionListener(interactionListener);
runOnUiThread(new Runnable() {
@Override
public void run() {
userTextInput.setEnabled(true);
}
});
}
@Override
public void onError(Exception e) {
Log.e(TAG, "initialize.onError: ", e);
}
});
}