Inicialización del SDK del cliente Android de Oracle en su aplicación
Esto es lo que necesita saber sobre la inicialización del SDK de Android en su aplicación.
Inicialización del SDK del cliente Android de Oracle en la clase Application
. En Inicialización del SDK se describen los distintos métodos que puede utilizar para inicializar el SDK. En el JavaDoc incluido con el SDK se describen todas las clases disponibles.
false
como segundo parámetro a la función de constructor BotsConfiguration.BotsConfigurationBuilder()
.import android.app.Application;
import oracle.cloud.bots.mobile.core.Bots;
import oracle.cloud.bots.mobile.core.BotsCallback;
import oracle.cloud.bots.mobile.core.BotsConfiguration;
import oracle.cloud.bots.mobile.core.BotsSDKException;
public class YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
try {
BotsConfiguration botsConfiguration = new BotsConfiguration.BotsConfigurationBuilder(<SERVER_URI>, false, getApplicationContext()) // Configuration to initialize the SDK
.channelId(<CHANNEL_ID>)
.userId(<USER_ID>)
.build();
Bots.init(this, botsConfiguration, new BotsCallback() { // Initialize the SDK
@Override
public void onSuccess(Response paramResponse) {
// Handle init success
}
@Override
public void onFailure(Response paramResponse) {
// Handle init failure
}
});
} catch (BotsSDKException e) {
// Handle Exceptions thrown by SDK
}
}
}
Si se conecta a un canal con la autenticación de cliente activada, debe realizar algunas modificaciones menores: junto con la transferencia de true
como segundo parámetro a la función de constructor BotsConfiguration.BotsConfigurationBuilder()
, también debe definir la propiedad authTokenProvider
con la instancia de tipo AuthenticationTokenProvider
que se puede utilizar para generar y transferir el token de JWT.
AuthenticationTokenProvider
, que sustituye a la función getAuthToken()
para generar y devolver un token de JWT. El SDK utilizará la función para generar un nuevo token cuando necesite establecer una nueva conexión y el token existente haya caducado. El código tendría un aspecto similar a este:import android.app.Application;
import oracle.cloud.bots.mobile.core.AuthenticationTokenProvider;
import oracle.cloud.bots.mobile.core.Bots;
import oracle.cloud.bots.mobile.core.BotsCallback;
import oracle.cloud.bots.mobile.core.BotsConfiguration;
import oracle.cloud.bots.mobile.core.BotsSDKException;
public class YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
try {
BotsConfiguration botsConfiguration = new BotsConfiguration.BotsConfigurationBuilder(<SERVER_URI>, true, getApplicationContext()) // Configuration to initialize the SDK
.authTokenProvider(new AuthTokenProvider())
.build();
Bots.init(this, botsConfiguration, new BotsCallback() { // Initialize the SDK
@Override
public void onSuccess(Response paramResponse) {
// Handle init success
}
@Override
public void onFailure(Response paramResponse) {
// Handle init failure
}
});
} catch (BotsSDKException e) {
// Handle Exceptions thrown by SDK
}
}
private class AuthTokenProvider implements AuthenticationTokenProvider {
@Override
public String getAuthToken() {
// Generate a new JWT Token and return
}
}
}
import oracle.cloud.bots.mobile.ui.ConversationActivity;
...
ConversationActivity.show(this);