Haga clic derecho en el paquete com.sap.flows
y seleccione Nuevo> Clase Java.
Especifique el nombre de la nueva clase MyApplication
.
Sustituye el código por la clase. MyApplication.java
con el código de abajo.
package com.sap.flows;
import android.app.Application;
import com.sap.cloud.mobile.foundation.authentication.AppLifecycleCallbackHandler;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
registerActivityLifecycleCallbacks(AppLifecycleCallbackHandler.getInstance());
}
}
Esta clase habilita el diálogo de autenticación básica para acceder a la actividad principal, de modo que se pueda visualizar.
Sa manifests/AndroidManifest.xml
archivo, agregue la entrada a continuación y cambie allowBackup
falso.
android:name=".MyApplication"
Modifique el proyecto para usar JDK 1.8 para origen y destino navegando a Archivo> Estructura del proyecto o haciendo clic en el icono de la barra de herramientas.
Cree un nuevo archivo de recursos de diseño en el res/layout
carpeta llamada splash_screen.xml
. Sustituya el siguiente código por su contenido. La pantalla de bienvenida se mostrará hasta que se complete el flujo de retorno o de a bordo.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageView android:id="@+id/splashscreen" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher_round"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Wiz App"
android:textAlignment="center"/>
</LinearLayout>
Reemplazar el código MainActivity.java
con el siguiente código.
package com.sap.flows;
//imports for entire Flows tutorial are added here
import android.app.Activity;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.sap.cloud.mobile.flow.Flow;
import com.sap.cloud.mobile.flow.FlowActionHandler;
import com.sap.cloud.mobile.flow.FlowContext;
import com.sap.cloud.mobile.flow.FlowManagerService;
import com.sap.cloud.mobile.flow.ServiceConnection;
import com.sap.cloud.mobile.flow.Step;
import com.sap.cloud.mobile.flow.onboarding.OnboardingContext;
import com.sap.cloud.mobile.flow.onboarding.basicauth.BasicAuthStep;
import com.sap.cloud.mobile.flow.onboarding.basicauth.BasicAuthStoreStep;
import com.sap.cloud.mobile.flow.onboarding.eulascreen.EulaScreenStep;
import com.sap.cloud.mobile.flow.onboarding.logging.LoggingStep;
import com.sap.cloud.mobile.flow.onboarding.presenter.FlowPresentationActionHandlerImpl;
import com.sap.cloud.mobile.flow.onboarding.storemanager.ChangePasscodeStep;
import com.sap.cloud.mobile.flow.onboarding.storemanager.PasscodePolicyStoreStep;
import com.sap.cloud.mobile.flow.onboarding.storemanager.SettingsDownloadStep;
import com.sap.cloud.mobile.flow.onboarding.storemanager.SettingsStoreStep;
import com.sap.cloud.mobile.flow.onboarding.storemanager.StoreManagerStep;
import com.sap.cloud.mobile.flow.onboarding.welcomescreen.WelcomeScreenStep;
import com.sap.cloud.mobile.flow.onboarding.welcomescreen.WelcomeScreenStoreStep;
import com.sap.cloud.mobile.foundation.common.EncryptionError;
import com.sap.cloud.mobile.foundation.common.SettingsParameters;
import com.sap.cloud.mobile.foundation.configurationprovider.ConfigurationProvider;
import com.sap.cloud.mobile.foundation.configurationprovider.JsonConfigurationProvider;
import com.sap.cloud.mobile.foundation.logging.Logging;
import com.sap.cloud.mobile.foundation.securestore.OpenFailureException;
import com.sap.cloud.mobile.onboarding.launchscreen.LaunchScreenSettings;
import com.sap.cloud.mobile.onboarding.qrcodereader.QRCodeConfirmSettings;
import com.sap.cloud.mobile.onboarding.qrcodereader.QRCodeReaderSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.MalformedURLException;
import ch.qos.logback.classic.Level;
import okhttp3.OkHttpClient;
public class MainActivity extends AppCompatActivity {
private FlowManagerService flowManagerService;
private OnboardingContext flowContext;
private String appID = "com.sap.wizapp";
private static Logger LOGGER = LoggerFactory.getLogger(MyApplication.class);
private Logging.UploadListener myLogUploadListener;
private SettingsDownloadStep settingsDownloadStep = new SettingsDownloadStep();
private EulaScreenStep eulaScreenStep = new EulaScreenStep();
ServiceConnection connection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
// This is called when the connection with the service has been
// established, giving us the service object we can use to
// interact with the service. Because we have bound to a explicit
// service that we know is running in our own process, we can
// cast its IBinder to a concrete class and directly access it.
flowManagerService = ((FlowManagerService.LocalBinder)service).getService();
startOnboardingFlow();
}
public void onServiceDisconnected(ComponentName className) {
// This is called when the connection with the service has been
// unexpectedly disconnected -- that is, its process crashed.
// Because it is running in our same process, we should never
// see this happen.
flowManagerService = null;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.splash_screen);
initializeLogging(Level.TRACE);
LOGGER.debug("Log level in onCreate is: " + Logging.getRootLogger().getLevel().toString());
// Uncomment the below line to not show the passcode screen. Requires that Passcode Policy is disabled in the management cockpit
//settingsDownloadStep.passcodePolicy = null;
eulaScreenStep.setEulaVersion("0.1");
this.bindService(new Intent(this, FlowManagerService.class),
this.connection, Activity.BIND_AUTO_CREATE);
}
private void initializeLogging(Level level) {
Logging.ConfigurationBuilder cb = new Logging.ConfigurationBuilder()
.logToConsole(true)
.initialLevel(level); // levels in order are all, trace, debug, info, warn, error, off
Logging.initialize(this.getApplicationContext(), cb);
}
private void startOnboardingFlow() {
flowContext = new OnboardingContext();
// setting details on the welcome screen and store
WelcomeScreenStep welcomeScreenStep = new WelcomeScreenStep();
welcomeScreenStep.setApplicationId(appID);
welcomeScreenStep.setApplicationVersion("1.0");
welcomeScreenStep.setDeviceId(android.provider.Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID));
LaunchScreenSettings lss = new LaunchScreenSettings();
lss.setDemoAvailable(false);
lss.setLaunchScreenTitles(new String[]{"Wiz App"});
lss.setLaunchScreenHeadline("Now with Flows!");
lss.setLaunchScreenDescriptions(new String[] {"See how easy it is to onboard with Flows"});
lss.setLaunchScreenImages(new int[]{R.drawable.graphic_airplane});
welcomeScreenStep.setWelcomeScreenSettings(lss);
// adds the QR code activation screen during onboarding
//welcomeScreenStep.setProviders(new ConfigurationProvider[] {new JsonConfigurationProvider()});
// skips the Scan Succeeded screen after scanning the QR code
//QRCodeConfirmSettings qrcs = new QRCodeConfirmSettings();
//QRCodeReaderSettings qrcrs = new QRCodeReaderSettings();
//qrcrs.setSkipConfirmScreen(true);
//welcomeScreenStep.setQrCodeConfirmSettings(qrcs);
//welcomeScreenStep.setQrCodeReaderSettings(qrcrs);
// Creating flow and configuring steps
Flow flow = new Flow("onboard");
flow.setSteps(new Step[] {
new PasscodePolicyStoreStep(), // Creates the passcode policy store (RLM_SECURE_STORE)
welcomeScreenStep, // Shows the welcome screen and getting the configuration data
new BasicAuthStep(), // Authenticates with Mobile Services
settingsDownloadStep, // Get the client policy data from the server
new LoggingStep(), // available in 2.0.1 and above
new StoreManagerStep(), // Manages the Application Store (APP_SECURE_STORE), encrypted using passcode key
new BasicAuthStoreStep(), // Persists the credentials into the application Store
new WelcomeScreenStoreStep(), // Persists the configuration data into the application store
new SettingsStoreStep(), // Persists the passcode policy into the application store
eulaScreenStep // Presents the EULA screen and persists the version of the EULA into the application store
});
// Preparing the flow context
flowContext.setContext(getApplication());
flowContext.setFlowPresentationActionHandler(new FlowPresentationActionHandlerImpl(this));
flowManagerService.execute(flow, flowContext, new FlowActionHandler() {
@Override
public void onFailure(Throwable t) {
// flowManagerService failed to execute so create an alert dialog to inform users of errors
LOGGER.debug("Failed to onboard. " + t.getMessage());
showAlertDialog("Onboard", t);
}
@Override
public void onSuccess(FlowContext result) {
initializeLogging(Level.DEBUG); // TODO remove when https://support.wdf.sap.corp/sap/support/message/1980000361 is fixed
LOGGER.debug("Successfully onboarded");
// remove the splash screen and replace it with the actual working app screen
getSupportActionBar().show();
setContentView(R.layout.activity_main);
}
});
}
public void onUploadLog(View view) {
LOGGER.debug("In onUploadLog");
}
public void onChange(View view) {
LOGGER.debug("In onChange");
}
public void onReset(View view) {
LOGGER.debug("In onReset");
}
public void showAlertDialog(String flow, Throwable t) {
// create an alert dialog because an error has been thrown
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Failed to execute " + flow + " Flow");
alertDialog.setMessage((t.getMessage().equals("Eula Rejected") ? "EULA Rejected" : "" + t.getMessage()));
// dismisses the dialog if OK is clicked, but if the EULA was rejected then app is reset
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// if (t.getMessage().equals("Eula Rejected") || flow.equals("Onboard")) {
// startResetFlow();
// }
dialog.dismiss();
}
});
// changes the colour scheme
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.parseColor("#008577"));
}
});
alertDialog.show();
}
}
Reemplazar el XML res/layout/activity_main.xml
con el siguiente código que agregará tres botones, reiniciar, cambiar y cargar el registro.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.sap.flows.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<Button
android:id="@+id/b_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onReset"
android:text="Reset" />
<Button
android:id="@+id/b_change"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onChange"
android:text="Change" />
<Button
android:id="@+id/b_uploadLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onUploadLog"
android:text="Upload Log" />
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
Haga clic derecho en la carpeta res, seleccione Nuevo> Directorio y nombrarlo crudo.
Haga clic derecho en el crudo carpeta, seleccione Nuevo> Archivo y nombrarlo configurationprovider.json
.
Copie el contenido a continuación en el archivo.
{
"auth":[{"type":"basic.default","config":{},"requireOtp":false}],
"host":"hcpms-p1743065160trial.hanatrial.ondemand.com",
"port":443,
"protocol":"https",
"appID":"com.sap.wizapp"
}
Tenga en cuenta que si este archivo no está disponible, una pantalla le pedirá al usuario que escanee un código QR que contenga los datos integrados o ingrese su dirección de correo electrónico (para obtener los datos de configuración del servicio de descubrimiento).
Actualice el valor de host para que coincida con su host de servicios móviles. Este valor se puede ver en la cabina de administración en API como se muestra a continuación.